I have written two version of the program and new to python. I am not able to understand what went wrong while printing a Fibonacci series. The first program prints the Fibonacci series correctly but the second program has an issue. Please let me know what's wrong.
Program 1
def fib(n): # write Fibonacci series up to n
"""Print a Fibonacci series up to n."""
a, b = 0, 1
while a < n:
print(a, end=' ')
a, b = b, a+b
print()
# Now call the function we just defined:
fib(2000)
Output
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
Program 2
# Let make a function that prints a Fibonacci
def fib(n): # write Fibonacci series up to n
"""Print a Fibonacci series up to n."""
a = 0
b = 1
while a < n:
print(a, end=" ")
a = b
b = a+b
fib(2000)
Output
0 1 2 4 8 16 32 64 128 256 512 1024