  ## Python Practice Test MCQ Certified Go from 0 to Expert hero Set 29

##### What will be the output of the following Python code?`def test(i,j): if(i==0): return j else: return test(i-1,i+j)print(test(4,7))`

Options are :

• 13
• 7
• Infinite loop
• 17

##### What will be the output of the following Python code?`l=[]def convert(b): if(b==0): return l dig=b%2 l.append(dig) convert(b//2)convert(6)l.reverse()for i in l: print(i,end="")`

Options are :

• 011
• 110
• 3
• Infinite loop

##### What is tail recursion?

Options are :

• A recursive function that has two base cases
• A function where the recursive functions leads to an infinite loop
• A recursive function where the function doesn't return anything and just prints the values
• A function where the recursive call is the last thing executed by the function

Answer :A function where the recursive call is the last thing executed by the function

##### Observe the following Python code?`def a(n): if n == 0: return 0 else: return n*a(n - 1)def b(n, tot): if n == 0: return tot else: return b(n-2, tot-2)`

Options are :

• Both a() and b() aren't tail recursive
• Both a() and b() are tail recursive
• b() is tail recursive but a() isn't
• a() is tail recursive but b() isn't

Answer :b() is tail recursive but a() isn't

##### Which of the following statements is false about recursion?

Options are :

• Every recursive function must have a base case
• Infinite recursion can occur if the base case isn't properly mentioned
• A recursive function makes the code easier to understand
• Every recursive function must have a return value

Answer :Every recursive function must have a return value

##### What will be the output of the following Python code?`def fun(n): if (n > 100): return n - 5 return fun(fun(n+11)); print(fun(45))`

Options are :

• 50
• 100
• 74
• Infinite loop

Options are :

• True
• False

##### What happens if the base condition isn't defined in recursive programs?

Options are :

• Program gets into an infinite loop
• Program runs once
• Program runs n number of times where n is the argument given to the function
• An exception is thrown

Answer :Program gets into an infinite loop

##### Which of these is not true about recursion?

Options are :

• Making the code look clean
• A complex task can be broken into sub-problems
• Recursive calls take up less memory
• Sequence generation is easier than a nested iteration

Answer :Recursive calls take up less memory

##### Which of these is not true about recursion?

Options are :

• It's easier to code some real-world problems using recursion than non-recursive equivalent
• Recursive functions are easy to debug
• Recursive calls take up a lot of memory
• Programs using recursion take longer time than their non-recursive equivalent

Answer :Recursive functions are easy to debug

##### What will be the output of the following Python code?`def a(n): if n == 0: return 0 elif n == 1: return 1 else: return a(n-1)+a(n-2)for i in range(0,4): print(a(i),end=" ")`

Options are :

• 0 1 2 3
• An exception is thrown
• 0 1 1 2 3
• 0 1 1 2

##### Which type of copy is shown in the following python code?`l1=[[10, 20], [30, 40], [50, 60]]ls=list(l1)ls[[10, 20], [30, 40], [50, 60]] `

Options are :

• Shallow copy
• Deep copy
• memberwise
• All of the mentioned

##### What will be the output of the following Python code?`l=[2, 3, [4, 5]]l2=l.copy()l2=88ll2`

Options are :

• [88, 2, 3, [4, 5]] [88, 2, 3, [4, 5]]
• [2, 3, [4, 5]] [88, 2, 3, [4, 5]]
• [88, 2, 3, [4, 5]] [2, 3, [4, 5]]
• [2, 3, [4, 5]] [2, 3, [4, 5]]

Answer :[2, 3, [4, 5]] [88, 2, 3, [4, 5]]

##### In _______________ copy, the base address of the objects are copied. In _______________ copy, the base address of the objects are not copied.

Options are :

• deep. shallow
• memberwise, shallow
• shallow, deep
• deep, memberwise

Options are :

• True
• False

##### What will be the output of the following Python code and state the type of copy that is depicted?`l1=[2, 4, 6, 8]l2=[1, 2, 3]l1=l2l2`

Options are :

• [2, 4, 6, 8], shallow copy
• [2, 4, 6, 8], deep copy
• [1, 2, 3], shallow copy
• [1, 2, 3], deep copy

Answer :[1, 2, 3], shallow copy

Options are :

• False, False
• False, True
• True, True
• True, False

Options are :

• True
• False
• Error

##### What will be the output of the following Python code?`l1=[10, 20, 30, ]l2=copy.deepcopy(l1)l1=90l1l2`

Options are :

• [10, 20, 30, ] [10, 20, 30, 90]
• Error
• [10, 20, 30 ] [10, 20, 30, ]
• [10, 20, 30, ] [10, 20, 30, ]

Answer :[10, 20, 30 ] [10, 20, 30, ]

##### In ____________________ copy, the modification done on one list affects the other list. In ____________________ copy, the modification done on one list does not affect the other list.

Options are :

• shallow, deep
• memberwise, shallow
• deep, shallow
• deep, memberwise

##### What will be the output of the following Python code?`l1=[1, 2, 3, (4)]l2=l1.copy()l2l1`

Options are :

• [1, 2, 3, (4)] [1, 2, 3, 4]
• [1, 2, 3, 4] [1, 2, 3, (4)]
• [1, 2, 3, 4] [1, 2, 3, 4]
• [1, 2, 3, (4)] [1, 2, 3, (4)]

Answer :[1, 2, 3, 4] [1, 2, 3, 4]

##### What will be the output of the following Python code?`def check(n): if n < 2: return n % 2 == 0 return check(n - 2)print(check(11))`

Options are :

• False
• True
• 1
• An exception is thrown

##### What is the base case in the Merge Sort algorithm when it is solved recursively?

Options are :

• n=0
• n=1
• A list of length one
• An empty list

Answer :A list of length one

##### What will be the output of the following Python code?`a = [1, 2, 3, 4, 5]b = lambda x: (b (x[1:]) + x[:1] if x else []) print(b (a))`

Options are :

• 1 2 3 4 5
• [5,4,3,2,1]
• []
• Error, lambda functions can't be called recursively

##### What will be the output of the following Python code?`odd=lambda x: bool(x%2)numbers=[n for n in range(10)]print(numbers)n=list()for i in numbers: if odd(i): continue else: break`

Options are :

• [0, 2, 4, 6, 8, 10]
• [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
• [1, 3, 5, 7, 9]
• Error

Answer :[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Options are :

• False True
• False False
• True True
• True False

Options are :

• Error
• 10
• 24
• No output

Options are :

• [1, 4, 5 ]
• Error
• [-2, -3]
• [1, -2, -3]

Options are :

• [-4, 16]
• Error
• -4 16

##### What will be the output of the following Python code?`l=[1, -2, -3, 4, 5]def f1(x): return x<-1m1=map(f1, l)print(list(m1))`

Options are :

• [False, False, False, False, False]
• [False, True, True, False, False]
• [True, False, False, True, True]
• [True, True, True, True, True]

Answer :[False, True, True, False, False]

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions