Question

In: Computer Science

I am building a tik tac toe board using python and the function I am using...

I am building a tik tac toe board using python and the function I am using is not working to check to see if the board is full. I'll include the code for the board and the function to check if it is full. X's and O's are being inserted and the function is suppose to stop running when is_full(board) returns True. ch is either x or o

board = []

   for i in range(3):

    board.append([])

    for j in range(3):

    board[i].append(' ')

   return board

def is_full(board):

   """ Checking for board full """

   for lst in board:

    for ch in lst:

    if ch == ' ':

    return False

Solutions

Expert Solution

def is_full(board):
    # checks if the list contains either 'X' or 'O'
    # if character is not among both it returns False
    # if all the characters are among them it returns True
    for lst in board:
       for ch in lst:
           if ch not in ['X','O']:
               return False

    return True

board = [
    ['X', 'O', 'X'],
    ['O', 'X', 'O'],
    ['O', 'O', 'X'],
]
print(is_full(board))

board = [
    ['X', ' ', 'X'],
    ['O', 'X', 'O'],
    ['O', 'O', 'X'],
]
print(is_full(board))

Code :

Output :


Related Solutions

I am having an issue with the Java program with a tic tac toe. it isn't...
I am having an issue with the Java program with a tic tac toe. it isn't a game. user puts in the array and it prints out this. 1. Write a method print that will take a two dimensional character array as input, and print the content of the array. This two dimensional character array represents a Tic Tac Toe game. 2. Write a main method that creates several arrays and calls the print method. Below is an example of...
please create a tic tac toe game with python using only graphics.py library
please create a tic tac toe game with python using only graphics.py library
Write a class (and a client class to test it) that encapsulates a tic-tac-toe board. A...
Write a class (and a client class to test it) that encapsulates a tic-tac-toe board. A tic-tac-toe board looks like a table of three rows and three columns partially or completely filled with the characters X and O. At any point, a cell of that table could be empty or could contain an X or an O. You should have one instance variable, a two-dimensional array of values representing the tic-tac-toe board. This game should involve one human player vs....
Write a class (and a client class to test it) that encapsulates a tic-tac-toe board. A...
Write a class (and a client class to test it) that encapsulates a tic-tac-toe board. A tic-tac-toe board looks like a table of three rows and three columns partially or completely filled with the characters X and O. At any point, a cell of that table could be empty or could contain an X or an O. You should have one instance variable, a two-dimensional array of values representing the tic-tac-toe board. This game should involve one human player vs....
Program Description, Interfaces, and Functionality To create a Python tic-tac-toe game, use Python's randint function from...
Program Description, Interfaces, and Functionality To create a Python tic-tac-toe game, use Python's randint function from the random module to control the computer's moves. To determine if the game has been won or is a tie/draw, write at least the func- tions: def move(), def check_cols(), def check_diag1(), def check_diag2(), def check_rows(), and def print_board(). Four of the functions will check if a winning state exist. To win tic-tac-toe, a user needs to have three of the same game pieces,...
Python Code Needed Two-Player, Two-Dimensional Tic-Tac-Toe Write a script to play two-dimensional Tic-Tac-Toe between two human...
Python Code Needed Two-Player, Two-Dimensional Tic-Tac-Toe Write a script to play two-dimensional Tic-Tac-Toe between two human players who alternate entering their moves on the same computer. Create a 3-by-3 two-dimensional array. Each player indicates their moves by entering a pair of numbers representing the row and column indices of the square in which they want to place their mark, either an 'X' or an 'O'. When the first player moves, place an 'X' in the specified square. When the second...
Write a program that plays tic-tac-toe. The tic-tac-toe game is played on a 3 × 3...
Write a program that plays tic-tac-toe. The tic-tac-toe game is played on a 3 × 3 grid as shown below: The game is played by two players, who take turns. The first player marks moves with a circle, the second with a cross. The player who has formed a horizontal, vertical, or diagonal sequence of three marks wins. Your program should draw the game board, ask the user for the coordinates of the next mark (their move), change the players...
In Python: Please complete the following two tasks in Tic Tac Toe: 1. Allow the user...
In Python: Please complete the following two tasks in Tic Tac Toe: 1. Allow the user to choose heads/tails to see if the user goes first or the computer and alter your code accordingly. 2. Allow the user to play again. Add a simple strategy for the AI to play against the user.
PLEASE READ VERY CAREFULLY write a client.py and server.py file for tic-tac-toe IN PYTHON with the...
PLEASE READ VERY CAREFULLY write a client.py and server.py file for tic-tac-toe IN PYTHON with the following restrictions (SO WRITE TWO FILES THAT PLAY PYTHON THROUGH A SOCKET) Use a 5 x 5 grid (dimensions are subject to change, so use constants for NUM_ROWS and NUM_COLS) Use 'X' for player 1 and 'O' for player 2 (symbols and the number of players is subject to change, so use constants) Each player can make 1 move per turn before having to...
Stewart invented “Max” a board game similar to “Tic Tac Toe.” In May 2017, Stewart began...
Stewart invented “Max” a board game similar to “Tic Tac Toe.” In May 2017, Stewart began negotiating with Big Board, Inc., to license “Max” for distribution outside the United States. On June 11, 2017, the parties met and orally discussed terms. As compensation, Big Board promised to pay Stewart the amount due from another board game he had developed for Big Board two years ago. On June 26, 2017, Lisa, a Big Board employee, sent Stewart an email titled “Max...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT