hi, trying to pass a variable as parameter, then change it and return it for each players turn in a modified tic tac toe program – but when the program reaches next function it seems to change the value of the variable? simplified code below. as im returning currentPlayer im not sure why its reverting back to B
currentPlayer = "Player B" def playerSwitch(currentPlayer): ### So the first turn is Player A if currentPlayer == "Player B": currentPlayer = "Player A" else: currentPlayer = "Player B" print(currentPlayer) # Prints as A return currentPlayer def inputChecker(board, wordList, currentPlayer, playerState, emptySpace): print(currentPlayer) # Prints as B? wordInp = input(currentPlayer + "! Choose a word from the list: ") numInp = int(input("Choose a position from the board 1-9: ")) - 1
submitted by /u/st-ides_heaven
[link] [comments]
r/learnpython hi, trying to pass a variable as parameter, then change it and return it for each players turn in a modified tic tac toe program – but when the program reaches next function it seems to change the value of the variable? simplified code below. as im returning currentPlayer im not sure why its reverting back to B currentPlayer = “Player B” def playerSwitch(currentPlayer): ### So the first turn is Player A if currentPlayer == “Player B”: currentPlayer = “Player A” else: currentPlayer = “Player B” print(currentPlayer) # Prints as A return currentPlayer def inputChecker(board, wordList, currentPlayer, playerState, emptySpace): print(currentPlayer) # Prints as B? wordInp = input(currentPlayer + “! Choose a word from the list: “) numInp = int(input(“Choose a position from the board 1-9: “)) – 1 submitted by /u/st-ides_heaven [link] [comments]
hi, trying to pass a variable as parameter, then change it and return it for each players turn in a modified tic tac toe program – but when the program reaches next function it seems to change the value of the variable? simplified code below. as im returning currentPlayer im not sure why its reverting back to B
currentPlayer = "Player B" def playerSwitch(currentPlayer): ### So the first turn is Player A if currentPlayer == "Player B": currentPlayer = "Player A" else: currentPlayer = "Player B" print(currentPlayer) # Prints as A return currentPlayer def inputChecker(board, wordList, currentPlayer, playerState, emptySpace): print(currentPlayer) # Prints as B? wordInp = input(currentPlayer + "! Choose a word from the list: ") numInp = int(input("Choose a position from the board 1-9: ")) - 1
submitted by /u/st-ides_heaven
[link] [comments]