For example, a common initialization in Python looks like this:
The mechanism is often implemented using a while loop that continues until a winner is declared or the board fills up (though win detection is typically reserved for Part 2 or Part 3). Inside the loop, the program prompts the current player for a move, validates the input (checking if the chosen cell is within range and empty), and then places the mark. After a successful move, the program switches the player:
board = [" " for _ in range(9)] Or, in a simpler, more transparent form: