1

if

a, b = 0, 1

means

a = 0 
b = 1 

then

a, b = b , a + b

should be

a = b 
b = a + b 

but if I use that in fib function at (https://docs.python.org/3/tutorial/controlflow.html#defining-functions) it does not work. can some one help me understand how it work ?

so output of

def fib(n):
    a, b = 0, 1
    while a < n:
        print(a, end = ' ')
        a = b 
        b = a + b 
    print()

fib(50)

is 0 1 2 4 8 16 32

Devesh Kumar Singh
  • 20,259
  • 5
  • 21
  • 40
Ashish
  • 14,295
  • 21
  • 82
  • 127
  • 1
    I think it is important to point out a logic error. `a = b` is the problem. So the next line `b = a + b` is actually `b + b`. – Marc Jul 12 '19 at 20:03

0 Answers0