import sys
def Factorial(i):
if i == 1:
return 1
else:
return i*Factorial(i-1)
sys.getrecursionlimit()
factorials = []
OOB = []
for i in range(1,3001):
try:
factorials.append(Factorial(i))
except RecursionError:
OOB.append(i)
print(OOB)
sys.getrecursionlimit() returns the max recursion depth as 3000. However, the function Factorial() returns a RecursionError for all i>2984 [The list 'OOB' contained all 2985 ≤ i ≤ 3000] As per the default system recursion depth, shouldn't the limit be till i = 2998 or i = 2999 ? Why is there a discrepancy here? If this question indicates a flaw in my understanding of recursion depth, please explain/guide to resources.