why does my Fibonacci code outcome change with changing the condition like below?

44 Views Asked by At
def fib(limit):
    a, b = 0, 1

    while a < limit:
        yield a
        a, b = b, a + b

x = fib(100)
for value in x:
    print(value, end="  ")

if you change the condition like below the outcome is not Fibonacci. Why?

def fib(limit):
    a = 0
    b = 1

    while a < limit:
        yield a
        a = b
        b = a + b
x = fib(100)
for value in x:
    print(value, end="  ")
0

There are 0 best solutions below