I am new to both programming (both in general and in Python) and to this community.
Following are two versions of the Fibonacci code, one attempted by me on my own, and the other from the Python documentation. The latter works but mine does not, and the only difference I can see between the two codes is that I have reassigned "a" and "b" on different lines in the while loop, whereas the one from Python doc. has assigned them on the same line.
In fact, when I reassign new values for a and b in my code on the same line, I get the correct output - but I dont know why? Why does it matter in this case on which line the values are reassigned?
#My own version of the fibonacci code. o/p as 1 2 4 8
a, b=0,1
while b<10:
print(b, end=" ")
a=b
b=a+b
#Python's doc version which works
a, b = 0, 1
while b < 10:
print(b, end=" ")
a, b = b, a+b