I want to save the output (0,1,1,2,3) of for-loop to the file but my code writes just the last value (3) of loop. How can I fix it?
#!/usr/bin/python
def fib(n):
a, b = 0, 1
for i in range(0, n):
a, b = b, a + b
return a
for c in range(0, 5):
print(fib(c))
file=open("fib.txt","w")
s = str(fib(c))
file.write(s+"\n")
# file.write("%s\n" % fib(c))
file.close()