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
PYTHON (Game: Tic-tac-toe): Write a program that plays the tic-tac-toe game. Two players take turns clicking...
PYTHON (Game: Tic-tac-toe): Write a program that plays the tic-tac-toe game. Two players take turns clicking an available cell in a 3 x 3 grid with their respective tokens (either X or O). When one player has placed three tokens in a horizontal, vertical, or diagonal row on the grid, the game is over and that player has won. A draw (no winner) occurs when all the cells in the grid have been filled with tokens and neither player has...
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....
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...
I need a good pseudocode for C++ for a tic tac toe program.
I need a good pseudocode for C++ for a tic tac toe program.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT