Professional Documents
Culture Documents
Lec 17 BB
Lec 17 BB
def f(b):
return a*b
a=0
print ('f(3) returns ', f(3))
print ('a is ' ,a)
What does this function print?
def f(b):
a =6
return a*b
a=0
print ('f(3) returns ', f(3))
print ('a is ' ,a)
What does this function print?
def f(b):
global a
a =6
return a*b
a=0
print ('a is ' ,a)
print ('f(3) returns ', f(3))
print ('a is ' ,a)
What does this function print?
def h(n):
print('Start h')
print(1/n)
print(n)
def g(n):
print('Start g')
h(n-1)
print(n)
def f(n):
print('Start f')
g(n-1)
print(n-1)
print(n)
n=4
f(n)
What does this function print?
def rec_printer(n):
print(n)
rec_printer(n-1)
rec_printer(10)
def itr_printer(n):
while True:
print(n)
n=n-1
itr_printer(10)
def reverse(str):
if (str == ''):
return str
else:
return reverse(str[1:]) + str[0]
print (reverse("Hello"))
Now the reverse recursion, always return to the caller
In class Exercise