You should complete the following exercises without using a computer, though you may consult your textbook. You should write your answers by hand and turn them in on paper.
Consider the functions defined below. What does main()
print?
def foo(a):
b = 3*a + 2
return b
def bar(x,y):
return foo(x) + foo(y)
def main():
print "The value is " + str(bar(2,3))
Consider the functions defined below. What is printed by main2()
?
def f1():
print "mushroom"
def f2():
f1()
print "badger"
f1()
def f3(n):
f2()
if n > 5:
print "snake"
f1()
else:
print "snaaaaake"
def main2():
f3(2)
f3(6)