Jul-10-2018, 06:39 AM
Hello,
Would anyone be able to help me with getting my Tic Tac Toe game to work pls?
I am trying to make it so that if the users input is invalid, eg, a letter or not in the range of 0-8,
it prints out "please enter a valid number!"
This is what i have so far:
thanks.
Would anyone be able to help me with getting my Tic Tac Toe game to work pls?
I am trying to make it so that if the users input is invalid, eg, a letter or not in the range of 0-8,
it prints out "please enter a valid number!"
This is what i have so far:
def chooseMove (boardValues): ###This is the players choice of where to go. (the player starts first always in this game.) validMove = False while (not validMove): printGameBoard(boardValues) squareChoice = int(input("Choose a square!")) -1 # takes away 1 from the chosen value by the player because the actual values of the board are 1 less than what they choose. if boardValues[squareChoice] != "X" and boardValues[squareChoice] != "O": ## checks to see that the chosen square is not already occupied. boardValues[squareChoice] = "X" validMove = True elif squareChoice not in range(0, 9): print("\nAnswer is not a number! please enter a valid number!") continue except ValueError: print("\nAnswer is not a number! please enter a valid number!") continue else: print("Please choose a free square!") return checkForWin(boardValues)so basically i do know that the elif square choice part is wrong but dont know how to fix it so if someone could help me would be appreciated.
thanks.