0
tic tac toe game TypeError
I was trying to make a simple tic tac toe game and I am always stumbling open a TypeError: "not all arguments converted during string formatting" I tried putting the player_turn()'s block of code in the main() while but that isn't working either. Any ideas what might be the reason for the incorrect execution?? https://code.sololearn.com/cMoDPxDXYfno/?ref=app
4 Answers
+ 1
on the player turn you change the board list value to O (or X).
that means value%3 in print board function no longer valid when it reach the element that has been replaced by the player (O|X). since the value is no longer a number.
you should itterate the board by the index not by value
+ 1
its
for index, value in enumerate
0
Taste thanks it worked by iterating by index (i used range(len)) I still have a question though why did the following replacement didn't work:
def print_board(board):
for value, index in enumerate(board, start=1):
print(f'{value:^3}', end='\n\n' if index % 3 == 0 else '-')
0
Taste ah silly me, Thank you for the help.