[Solved] Why is my variable not updating in the while loop? [closed]


It states “player 1” continuously because it uses n to figure that out, and n never changes in your loop.

If you want to cycle through the players, you’ll need to modify n with something like (at the end of the loop, but within it):

n = (n + 1) % 4 # gives 0, 1, 2, 3, 0, 1, ...

For example, you can see how this works in the following transcript:

>>> n = 0
>>> for _ in range(10):
...     print(n+1)
...     n = (n + 1) % 4
...
1
2
3
4
1
2
3
4
1
2

9

solved Why is my variable not updating in the while loop? [closed]