Basically I'm quite new to Python, but ive written a code for the Fibonacci Sequence and it doesn't work, i've compared it online and its pretty much the same but when i write it slightly differently, it works! - But I have no idea why, can anyone shed some light on why it is behaving this way?
This code has been built and tested in the Python 3.3.2 Shell.
Working Code:
def fib(n):
a, b = 0, 1
while b < n:
print(b)
a, b = b, b + a
Non-Working Code:
def fib(n):
a = 0
b = 1
while b < n:
print(b)
a = b
b = b + a
I'm completely confused as to why it only works when the variables are grouped together and not when they are separate.