Hi all,
Python newbie here. I'm confused as to why after running the below function, when I call one of the variables defined within that function, I receive an error message (that the variable is undefined). My code is below:
Python newbie here. I'm confused as to why after running the below function, when I call one of the variables defined within that function, I receive an error message (that the variable is undefined). My code is below:
def player_input(): player1_mark = input("Please pick a marker 'X' or 'O'") player2_mark = '' if player1_mark=='X': player2_mark='O' elif player1_mark=='O': player2_mark='X' print("Player 1 is: " + player1_mark) print("Player 2 is: " + player2_mark)In particular, after defining player1_mark, I get an undefined error when I try to retrieve "player2_mark" outside of the function, even though executing the function successfully prints both variables. Can anyone help out with this? Thanks!