Hello everyone, I have to output a fibonacci sequence to a file, I tried to do this with a for loop and \n characters to output one number of the series on a new line, however both of these goals fail and I feel stuck, here's the code, my apologies for the Dutch variable names: ```py
fib_cache = {}
memoteller = 0
bestandsnaam = 'fib.txt'
def fibonacci_memoization(n):
global memoteller, fib_cache
if n <= 0:
return 0
elif n == 1:
return 1
Check if the result is already within the cache.
if n in fib_cache:
return fib_cache[n]
If not, calculate it recursively and store it in the cache.
fib_value = fibonacci_memoization(n - 1) + fibonacci_memoization(n - 2)
fib_cache[n] = fib_value
memoteller +=2
return fib_value
for i in range(500):
with open(bestandsnaam, 'w') as doc:
doc.write(str((fibonacci_memoization(i)))+'\n')
expected output: 0\n1\n1\n2\n3\n5\n8\n...
actual output for i in range(500): 86168291600238450732788312165664788095941068326060883324529903470149056115823592713458328176574447204501
Thanks in advance.