I am attempting to create a tic tac toe game, where the user input will be 1 - 9 on the numpad. When the user inputs a number it will check if that corresponding spot in the list is respresented with a space (" "), and if not, it will then replace that spot in the list with an X.
However, I keep getting the following error when the input provided by the user is just them hitting the enter key: if update_board[int(user_input)] == " ": ValueError: invalid literal for int() with base 10: ''
I provided the info on the code for context, but how can I check if user input is them just hitting the enter key? I have attempted to check if user_input == "", but that doesn't work either. I get the same error.
update_board = ["#"," "," "," "," "," "," "," "," "," "]
def player_turn():
# Take in player's input so it can be added to the display board.
user_input = input('Choose your position: ')
if update_board[int(user_input)] == " ":
valid_input = True
else:
valid_input = False
while not valid_input:
user_input = input("That is not an option, please try again.\n> ")
if update_board[int(user_input)] == " ":
valid_input = True
else:
valid_input = False
return int(user_input)
player1 = "X"
update_board[(player_turn())] = player1