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__)
  1. A. False True int
  2. B. True False int
  3. C. True True int
  4. 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

Exams that ask this topic