This they have:
def fib(n):
a, b = 0, 1
while a < n:
print a,
a, b = b, a+b
This is what I have:
def fib(n):
a = 0
b = 1
while a < n:
print a
a = b
b = b+a
The first returns the correct sequence when used, while mine continues with 0, 1, 2, 4, 8, 16, 32 ...
I am currently studying programming (no prior education in computer science), and it is clear that the problem is how I defined my variables. What is the difference between splitting variables with commas and splitting variables on a new line (assuming this is a problem)?
source
share