Common causes
- A recursive function is missing its base case (the condition that stops the recursion)
- The base case is present but is never reached due to a logic error
- The input data is deeply nested beyond the recursion limit
- Two functions calling each other infinitely (mutual recursion with no exit)
How to fix it
- Add or fix the base case in your recursive function — it must be reachable
- Add a print/debug at the top to trace how deep calls go: print(depth, value)
- Convert deep recursion to iteration using an explicit stack (list used as LIFO)
- As a last resort, increase the limit: import sys; sys.setrecursionlimit(5000) — but fix the root cause first
Example
Traceback (most recent call last):
File "app.py", line 3, in countdown
countdown(n - 1)
[Previous line repeated 996 more times]
RecursionError: maximum recursion depth exceededA countdown function called with countdown(-1) where the base case only stops at n == 0
Have a different error?
Paste any error message into the Error Translator to get an instant explanation.
