Linked Questions

Popular Questions

I'm currently building a tic tac toe game using Python3. Below is the code to ask players to choose a marker to start a game. I'm trying to return the input as below but it only runs once and even though when the input is wrong, it still runs. For example, when the player keeps putting letters other than X or O, I want to repeat the error input or go back to the beginning to make sure they put X or O. How can I fix this?

def player_input():
    marker = ''

    while marker != 'X' and marker != 'O':
        marker = input('Player1: Would you like to be X or O?')

        if marker == 'X':
            return ('Player1: X', 'Player2: O')
        if marker == 'O':
            return ('Player1: O', 'Player2: X')
            return input('Error:Please choose your marker to start a game. \nPlayer1: Would you like to be X or O?')

Related Questions