I'm trying to create a basic game, and one of the stages of this game is a user input of a value from 1-9. If a user enters one of those values, the game works, but if they simply hit return/enter when they get to the field, I get a value error. Below is the error:
<ipython-input-6-061a946b3a03> in <module>
----> 1 ttt_game()
<ipython-input-5-b42c27ce7032> in ttt_game()
36 while game_on == True:
37 while choose_first == 0:
---> 38 player_guess = int(input('Choose a space 1-9: '))
39 for position in board:
40 if position in board[player_guess] == ' ':
ValueError: invalid literal for int() with base 10: ''
I'm trying to figure out how to cause the input call to be either asked again, or to have the while loop restart and print a message like "Invalid entry, try again"
Here is the original code block if it helps.
while game_on == True:
while choose_first == 0:
player_guess = int(input('Choose a space 1-9: '))
for position in board:
if position in board[player_guess] == ' ':
board[player_guess] = 'X'
display_board(board)
if win_check(board,'x') == False:
pass
else:
display_board(board)
print('Player 1 has won the game!')
break
elif board[player_guess] == 'O':
print ('Space already chosen, choose another.')
pass
else:
choose_first = 1
pass