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


Traceback (most recent call last):
File "/Volumes/ELEMENTS/tic tac toe.py", line 29, in
File "/Volumes/ELEMENTS/tic tac toe.py", line 2, in after_every_move
TypeError: 'NoneType' object is not subscriptable

def after_every_move(board):

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" ],
         [" ","|"," ","|"," "],
         [" ","|"," ","|"," "]]

board = move(board)



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.