Skip to content

Latest commit

 

History

History
33 lines (22 loc) · 595 Bytes

File metadata and controls

33 lines (22 loc) · 595 Bytes

RecursionError: maximum recursion depth exceeded

Occurs when a recursive function does not have a proper base case and keeps calling itself indefinitely.

Reproduce

def recursive_function():
    return recursive_function()

recursive_function()

Error Message

RecursionError: maximum recursion depth exceeded

Fix

def recursive_function(n):
    if n <= 0:
        return 0
    return recursive_function(n - 1)

print(recursive_function(5))

Reflection

Forgot to add a base case, so the function kept calling itself until Python stopped it.