ProgrammingHardInfosys HackWithInfy · TCS CodeVita

What is printed?

What is printed?
def depth(n):
    return 0 if n == 0 else 1 + depth(n - 1)
try:
    print(depth(500))
    print(depth(5000))
except RecursionError:
    print('deep')
  1. A. 500 | deep
  2. B. 500 | 5000
  3. C. deep
  4. D. 1000 | deep

Correct answer: A. 500 | deep

CPython's default recursion limit is 1000 frames, so depth(500) succeeds and depth(5000) raises RecursionError, which the except branch catches.

More Python Programming questions

Exams that ask this topic