def fibonacci(n):
prev = curr = 1
yield 1
while curr < n:
yield curr
#1
prev = curr
curr = curr + prev
#or
#2
prev ,curr = curr, curr + prev
I have this fibonacci code here and I don't understand why when I assign:
prev = curr #first
curr = curr + prev #second
fibonacci(10)
results: 11248
gives a different answer then when I assign
prev ,curr = curr, curr + prev
fibonacci(10)
results: 112358
Which gives the correct Fibonacci sequence. Can someone please explain to me why is it so?
Thank you in advance for your input.
curr = 2*currcurrandprevin each step. Or add some debug/print lines