0

tictactoe loop error

I started to write a very simple tic tac toe game, to see how far I get. I wrote a piece of code for player 1 to make a move. It works as it should, except when I try to make a loop out of it to be able to make multiple moves. Then I get a traceback error after the first move. What did I do wrong? ----------------------------- board = ["_", "_", "_", "_", "_", "_", "_", "_", "_"] boardmove = {"A1": 0, "B1": 1, "C1": 2, "A2": 3, "B2": 4, "C2": 5, "A3": 6, "B3": 7, "C3": 8} movenumber = 9 user1_move = "" user2_move = "" def move1(user1_move): #input move print("Player 1: make a move") user1_move = input() if "A" not in user1_move and "B" not in user1_move and "C" not in user1_move: print("This is not a valid move") elif "1" not in user1_move and "2" not in user1_move and "3" not in user1_move: print("This is not a valid move") else: #replace chosen field with X board[boardmove.get(user1_move)] = "X" #print new board situation print(" A B C") print("") print("1 " + str(board[:3])) print("") print("2 " + str(board[3:6])) print("") print("3 " + str(board[6:])) print("") while movenumber > 0: move1(user1_move) movenumber -= 1

12th Apr 2022, 8:16 AM
Walter Zwiekhorst
Walter Zwiekhorst - avatar
3 Answers
+ 1
your code works fine, but it will not work correctly on SoloLearn's code Playground, because of while loop . Sololearn is not an interactive console. you have to enter all 9 moves at once. like : A1 A2 ... other moves C3 then submit
12th Apr 2022, 10:12 AM
Bahhaāµ£
Bahhaāµ£ - avatar
+ 1
Thanks! In the meantime I finished the whole Tic Tac Toe code in PyCharm and it works :-))))
12th Apr 2022, 10:17 AM
Walter Zwiekhorst
Walter Zwiekhorst - avatar
12th Apr 2022, 10:18 AM
Walter Zwiekhorst
Walter Zwiekhorst - avatar