Recursion in Python MCQs Exercise I
Ques 1
Recursion
Which of the following is true about recursion?
A recursive function must call itself two or three times.
B recursive function not have a base condition.
C Queue are used to analyse the recursion.
D All of the above.
Ques 2
Recursion
What is the output of the following Python Code?
def fun(a,b):
if a==0:
return 0
elif a%2!=0:
return fun(a//2, 2*b)+b
else:
return fun(a//2, 2*b)-b
def main():
print(fun(15,5))
main()
Ques 3
Recursion
What is the output of the following Python Code?
def fun(a):
if a<=1:
print(a,end="")
else:
fun(a//2)
print(a%2,end="")
fun(120)
A 01111000
B 0111110
C 1101000
D 1111000