PY
py
1
2
3
4
5
6
7
8
9
10
11
from functools import lru_cache
@lru_cache(maxsize = None) #For memoization.
def fib(n):
if n == 0 or n == 1: return n
else:
return fib(n - 1) + fib(n - 2)
for x in range(1, 2001):
print(f"{x} fibonacci number: {fib(x)}") #This does not raise a RecursionError even after the program is finished.
#print(fib(1000)) #This raises a RecursionError (If I comment the for loop code block above). Why?
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run