I ran into a something I did not expect when making a small program. I'm not including the whole program, just exemplifying the stick in the wheel, as it's part of a homework assignment. I'd just like some clarification on why the last "x = 1" is ignored.
x = 1
while x == 1:
print(x)
x = 2
while x == 2:
print(x)
x = 1
It looks to me that I should be getting a loop of 1, 2, 1, 2, 1, 2, 1, 2... But I only get 1, 2.
On the other hand, if I change the code to
x = 1
while x == 1:
print(x)
x = 2
while x == 2:
print(x)
x = 2 # 1 changed to 2
I get an endless loop of 1, 2, 2, 2, 2, 2, 2, 2, 2...
I've just started programming and I must say I'm a bit puzzled.