I need help to make a noughts and crosses game on python

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

Traceback (most recent call last):
File “/Volumes/ELEMENTS/tic tac toe.py”, line 29, in
after_every_move(board)
File “/Volumes/ELEMENTS/tic tac toe.py”, line 2, in after_every_move
print(board[0][0],board[0][1],board[0][2],board[0][3],board[0][4])
TypeError: ‘NoneType’ object is not subscriptable
<What do you expect to happen instead?>

```python

def after_every_move(board):
print(board[0][0],board[0][1],board[0][2],board[0][3],board[0][4])
print(board[1][0],board[1][1],board[1][2],board[1][3],board[1][4])
print(board[2][0],board[2][1],board[2][2],board[2][3],board[2][4])
print(board[3][0],board[3][1],board[3][2],board[3][3],board[3][4])
print(board[4][0],board[4][1],board[4][2],board[4][3],board[4][4])

def move(board):

if board[0][0] and board[0][2] == "O" and board[0][4] == " ":
    board[0][4] = "X"

elif board[0][0] and board[0][4] == "O" and board[0][2] == " ":
    board[0][2] = "X"

elif board[0][2] and board[0][4] == "O" and board[0][0] == " ":
    board[0][0] = "X"

print(“tic tac toe. you will be noughts (O). you will also go first”)
board = [[“O”,"|"," “,”|",“O” ],
["-","+","-","+","-"],
[" “,”|"," “,”|"," “],
[”-","+","-","+","-"],
[" “,”|"," “,”|"," "]]
after_every_move(board)

board = move(board)

after_every_move(board)

<do not remove the three backticks above>

You’re doing this:

>>> None[4]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not subscriptable

You probably meant to look something up in your board, but the variable you used was refering to None which represents lack of value. To fix that you’ll need to look at where you obtained that value, you can for example print out your board every so often to see where you lost track of it

what do you mean? which variable is this and how would i fix it?

Your error message says which line it happens which is enough to determine which variable it is.
To fix it, one would consider what value it should have been and where it should have been coming from, and then investigate where that value was “lost”

what would that value be? and how would i change it?

You already asked that. I responded with that that’s something you have to find out yourself, and then I suggested how you can go about that.

Asking the same thing again is at most going to get you an answer saying “see previous reply”

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.