I'm trying to remake Tic-Tac-Toe on python. But, it wont work.
I tried `
game_board = ['_'] * 9
print(game_board[0]) " | " (game_board[1]) ' | ' (game_board[2])
print(game_board[3]) ' | ' (game_board[4]) ' | ' (game_board[5])
print(game_board[6]) ' | ' (game_board[7]) ' | ' (game_board[8])
` but it returns
`
Traceback (most recent call last):
File "C:\Users\username\PycharmProjects\pythonProject\tutorial.py", line 2, in <module>
print(game_board[0]) " | " (game_board[1]) ' | ' (game_board[2])
~~~~~~~~~~~~~~~~~~~~~^~~~~~~
TypeError: unsupported operand type(s) for : 'NoneType' and 'str'
`
CodePudding user response:
Is this you want..!?
Code:-
game_board = ['_']*9
print(game_board[0] " | " (game_board[1]) ' | ' (game_board[2]))
print(game_board[3] ' | ' (game_board[4]) ' | ' (game_board[5]))
print(game_board[6] ' | ' (game_board[7]) ' | ' (game_board[8]))
Output:-
_ | _ | _
_ | _ | _
_ | _ | _
CodePudding user response:
This is because you put the parenthesis wrongly. It should be
game_board = ['_'] * 9
print(game_board[0] " | " (game_board[1]) ' | ' (game_board[2]))
print(game_board[3] ' | ' (game_board[4]) ' | ' (game_board[5]))
print(game_board[6] ' | ' (game_board[7]) ' | ' (game_board[8]))
CodePudding user response:
Please look at the error carefully to find your answer.
print(game_board[0]) " | " (game_board[1]) ' | ' (game_board[2])
~~~~~~~~~~~~~~~~~~~~~^~~~~~~
you have closed the bracket for game_board[0]. An additional '(' is to be used.
print( (game_board[0]) " | " .....
Understand errors to code properly.