ProgrammingVery hardGATE CS · Product-company placement
What is printed?
What is printed?
import sys
def depth(n):
try:
return depth(n + 1)
except RecursionError:
return n
d = depth(0)
print(d > 500, d < sys.getrecursionlimit(), type(sys.getrecursionlimit()).__name__)- A. False True int
- B. True False int
- C. True True int
- D. True True RecursionError
Correct answer: C. True True int
Python limits recursion depth (default limit 1000) and raises RecursionError, which can be caught like any exception. The depth reached is a little below the limit because some frames are already in use.
More Python Programming questions
- What is printed? python x = 0 def a(): global x x = 1 def b(): global x x += 10 b() return x print(a(), x)
- What is printed? python class A: n = [] m = 0 a, b = A(), A() a.n.append(1) a.m += 1 b.n = [2] print(A.n, A.m, a.n, b.n, a.m, b.m)
- What is printed? python x = [0, 1, 2, 3, 4, 5] print(x[1::2], x[-1::-2], x[::-1][::2] == x[::-2])
- What is printed? python m = [[1, 2, 3], [4, 5, 6]] t = list(zip(m)) print(t, [list(r) for r in zip(t)] == m, [x for row in m for x in…
- What is printed? python grid = [[0] 3 for in range(3)] for i in range(3): grid[i][i] = grid[i - 1][i - 1] + 1 print(grid[0][0]…
- What is printed? python a = [1, 2, 3] b = a a += a c = [1, 2] c.append(c) print(b, len(c), c[2][2][0], c)