Question 7
Back to Exercise
The program below stops with an error. Which statement correctly describes the problem?
def total(n):
return 0 if n == 0 else n + total(n - 1)
print(total(10_000))
- A RecursionError: the logic is right, but 10,000 nested calls exceed Python's default limit of about 1000; use a loop or sum(range(n + 1)) Correct
- B It prints 50005000
- C MemoryError
- D OverflowError
Correct Answer: Option A
Python keeps every frame until the base case is reached, and it has no tail-call optimisation.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!