Change turn in tic-tac-toe not working
<p>Just stuck in my code, was looking for others source, but there's other implementation, I must be blind or ... but it looks like functions are referring still to one variable, when in my beginning understanding if I call function which return 'change', and function return back to a place in code when it should not reach declared earlier variable, but that variable returned from function and next calling same function should again switch my variable (X and O), just cut a piece of this code: got X or O (what I'm choosing), printing variable correct, but then function output is X X X and so on... (I'm just started to learn, but just stuck here!)</p>

<pre><code>def choice():
    choice = input("You want to have x or o?: ")
    if choice == 'x':
        human = 'X'
        computer = 'O'
    else: 
        human = 'O'
        computer = 'X'
    return human, computer

human, computer = choice()
print("human is ", human)
print("computer is ", computer)

def next_player(turn):
    if turn == 'X':
        return 'O'
    else:
        return 'X'

turn = 'X'

print("turn is ", turn)
turn = next_player(turn) # was here: next_player(turn) and so below!!
print("after next player function turn is ", turn)
turn = next_player(turn)
print("after next player function turn is ", turn)
</code></pre>

<pre><code>def next_player(turn):
if turn == 'X':
    turn = 'O'
if turn == 'O':
    turn = 'X'
return turn
</code></pre>

<p>Where is this variable return being saved? I don't believe it is updating your 'turn' variable, hence why you are just printing 'X' over and over.</p>

python tic-tac-toe turn