0

In the program I need to write a function that takes the player's input for where they want to place the 'X' or 'O' for the Tic Tac Toe game, which would be a number between 0-8 and the function would also recognise invalid responses. An invalid response would be a number not between 0-8, anything that is not a number or a number that has been inputted previously.

What is the problem?

No matter what the input is the function recognises it as invalid, even if it should be valid.

Here is the code

def playerinput():
    
    print("Select the number on the board:")
    
    while True:
    
        playerchoice = input()
        if playerchoice.isdigit == True:
            if int(playerchoice) in validdata:
                validdata.pop(int(playerchoice))
                return int(playerchoice)
            else:
                print("That is not a valid input please enter a different value:")
            
            
        else:
            print("That is not a valid input please enter a different value:")

validdata is a global variable

validdata = [0,1,2,3,4,5,6,7,8]
famousgarkin
  • 13,687
  • 5
  • 58
  • 74
  • Take a look on [**this post**](https://stackoverflow.com/questions/61603764/total-beginner-wrote-a-tic-tac-toe-game-in-python-and-would-like-some-feedback/61604049#61604049) and a [**code review for the same post**](https://codereview.stackexchange.com/questions/241730/total-beginner-tic-tac-toe-game-in-python/241732#241732) – Saadi Toumi Fouad Sep 17 '20 at 08:01
  • Have you double checked `validdata` can be accessed from your program? (e.g. try to print it maybe...) – Fabio Veronese Sep 17 '20 at 08:03
  • 1
    `playerchoice.isdigit` is a function. You need to call it: `playerchoice.isdigit()`. – deceze Sep 17 '20 at 08:04
  • @deceze I'm not sure the linked duplicates will help very much. It seems like OP understands the theory (although this implementation is a bit heavy-handed); the problem is simply the typo that you pointed out. – Karl Knechtel Sep 17 '20 at 08:11
  • @FabioVeronese I just checked that 'validdata' can be accessed from the program. When testing I discovered that 'playerchoice.isdigit' is always False for some reason. Then I realised that I forgot to put the brackets that is why there was the error. – handsome100 Sep 17 '20 at 08:16
  • @deceze Yes you are correct that was the issue it works now. – handsome100 Sep 17 '20 at 08:17

0 Answers0