I'm having difficulty creating a program that switches between string "X" and "O" every time the function is ran.
So for example, the first time switcher() is ran, it prints "x," and the next time it runs, it prints "o," and third it prints "x," and so forth
I've been able to achieve this without a function and just using an if else loop, but I can't do it using a function
def switch(value):
if value == 0:
x = value
x + 1
print("value: " + str(x) + " | turn: x")
return x
else:
print("o")
return 0
x = 0
for i in range(4):
switch(x)
it outputs:
value: 0 | turn: x
value: 0 | turn: x
value: 0 | turn: x
value: 0 | turn: x
In order to achieve this, I make it so that when x = 0, it prints "X" and when it's 1 it prints "O," and then resets back to 0. It stays as 0 and only gives me x.