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.


a is the correct option





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()

  a) 71
  b) 73
  c) 75
  d) 77


c is the correct option





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


d is the correct option