ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import sys
sys.setrecursionlimit(50)
def f(n):
return 0 if n == 0 else 1 + f(n - 1)
try:
print(f(60))
except RecursionError:
print('deep')- A. 50
- B. deep
- C. 60
- D. RecursionError
Correct answer: B. deep
f(60) needs about 61 nested Python frames. Because the limit is 50, a RecursionError is raised, and the except block prints 'deep'. The exception is not caught by the function itself.
More Python Programming questions
- What is printed? python from functools import lrucache @lrucache(None) def f(n): return n if n < 2 else f(n - 1) + f(n - 2) print(f(90))
- What is printed? python from functools import lrucache import sys sys.setrecursionlimit(1000) @lrucache(None) def f(n): return 0 if n == 0…
- What is printed? python g = {1: [2, 3], 2: [4], 3: [], 4: []} stack = [1] out = [] while stack: u = stack.pop() out.append(u)…
- What is printed? python s = list(range(10)) print(s[8:2:-3], s[::-4], s[-3:])
- What is printed? python a = [1, 2, 3, 4, 5] a[1:3] = [9] 4 print(a)
- What is printed? python print(repr('abc'[5:]), repr('abc'[-10:2]), [1, 2][3:0:-1])