Interesting topic of recursion and stack overflow in class today and I wondered if there is any way of increasing the maximum recursion depth in Python? Wrote a quick function for finding the factorial of n using recursion:
def factorial(n):
if n == 1:
return n
else:
return n * factorial(n-1)
It can cope with factorial(994) but not factorial(995). The error given is:
RuntimeError: maximum recursion depth exceeded in comparison
Obviously a higher factorial can be found iteratively but, for the sake of argument and intrigue, can the maximum recursion depth be increased?