I want to make a tic tac toe game, and I do it this way, when the user enters the number 1 - 9, he makes X in the corresponding space on the grid. here is the function for this:
def move(inp): if inp == 1: one = " X |\t|\n_____________\n |\t|\n_____________\n |\t|" print one elif inp == 2: two = " | X |\n_____________\n |\t|\n_____________\n |\t|" print two elif inp == 3: three = " |\t| X\n_____________\n |\t|\n_____________\n |\t|" print three elif inp == 4: four = " |\t|\n____________\n X |\t|\n_____________\n |\t|" print four elif inp == 5: five = " |\t|\n_____________\n | X |\n_____________\n |\t|" print five elif inp == 6: six = " |\t|\n_____________\n |\t| X \n_____________\n |\t|" print six elif inp == 7: seven = " |\t|\n_____________\n |\t|\n_____________\n X |\t|" print seven elif inp == 8: eight = " |\t|\n_____________\n |\t|\n_____________\n | X |" print eight elif inp == 9: nine = " |\t|\n_____________\n |\t|\n_____________\n |\t| X " print nine
and so the grid appears with X in the right place. But then comes the next turn. And I want them to enter a new number, but keep the old X where it was. I thought: is there a way to combine this function with another parameter and make them put two Xs in the grid? So my question is: is there a function for this, and if not, how would I do it.
source share