Lec 17 BB

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 27

What does this function print?

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)

Who about this

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

You might also like