0

I am trying to make a basic tic-tac-toe game, so I need the user to input which part of the grid they would like to change into an "X" or "O" (required to use lists). The grid can be accessed using the syntax board[row][column].

board = [["1", "2", "3"],
    ["4", "X", "6"],
    ["7", "8", "9"]]

def EnterMove(board):
    player_move = input("Using board[row][column] syntax, make your move: ")
    if player_move in board:      # program doesn't recognize the input here
            board[player_move] = "O"
4
  • board is nested list so this if player_move in board will never work Commented Sep 13, 2020 at 7:37
  • Does this answer your question? How to check if an element is in a nested list? Commented Sep 13, 2020 at 7:39
  • is there any way to "un-nest" it so that it could work? Commented Sep 13, 2020 at 8:44
  • See the 2nd comment try that method Commented Sep 13, 2020 at 8:51

1 Answer 1

0

I don't think is the best practice, but

for row in board:
        if player_move in row:      
                row[row.index(player_move)] = "O"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.