'Printing Fibonacci Series having 2 similar codes but different outputs. Why?

Resolve CODE 2 to print output as CODE 1 and give the reason why both of the codes have different outputs.

Fibonacci Series

CODE 1

x = 0
y = 1
while x < 10:
    print(x)
    x, y = y, x + y

output 0 1 1 2 3 5 8

CODE 2

x = 0
y = 1
while x < 10:
    print(x)
    x = y
    y = x + y

Output 0 1 2 4 8



Solution 1:[1]

Those are simply not identical. In the first code block y becomes x+y and in the second code block y becomes 2*y.

Just a quick note the output of the second code block is 0 1 2 4 8 and not what you wrote (this was fixed).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1