I am relatively new to Python, so pardon my ignorance.
These two implementation of while loop for generating a Fib series is resulting in very different outputs.
The first one is returning the power series of 2, though I feel it is should be doing exactly what the latter is; which is returning the expected series.
The second while loop is obviously doing something right. I am guessing it has to do with the way the variables as being assigned while swapping values.
What is driving this difference?
Appreciate your inputs and help,
First while loop:
def fib(n):
x=0
y=1
while y < n:
print(y)
x = y
y = x + y
The second while loop:
x,y=0,1
while y < 100:
print(y)
x,y = y,x+y
xis modified before the new value ofyis calculated.