Hi,
I am completely new to programming and am strugling with my assignment Tic Tac Toe in Python code. Can somebody please help me by pointing out my mistakes? I am sure there are lots of mistakes, but I am blind to them and how to solve them.
I am completely new to programming and am strugling with my assignment Tic Tac Toe in Python code. Can somebody please help me by pointing out my mistakes? I am sure there are lots of mistakes, but I am blind to them and how to solve them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
def print_board(board): for row in board: print (row) def check_winner(board, current_player): if board[ 0 ][ 0 ] = = board[ 0 ][ 1 ] = = board[ 0 ][ 2 ] ! = "": return True elif board[ 1 ][ 0 ] = = board[ 1 ][ 1 ] = = board[ 1 ][ 2 ] ! = "": return True elif board[ 2 ][ 0 ] = = board[ 2 ][ 1 ] = = board[ 2 ][ 2 ] ! = "": return True elif board[ 0 ][ 0 ] = = board[ 1 ][ 0 ] = = board[ 2 ][ 0 ] ! = "": return True elif board[ 0 ][ 1 ] = = board[ 1 ][ 1 ] = = board[ 2 ][ 1 ] ! = "": return True elif board[ 0 ][ 2 ] = = board[ 1 ][ 2 ] = = board[ 2 ][ 2 ] ! = "": return True elif board[ 0 ][ 0 ] = = board[ 1 ][ 1 ] = = board[ 2 ][ 2 ] ! = "": return True elif board[ 2 ][ 0 ] = = board[ 1 ][ 1 ] = = board[ 0 ][ 2 ] ! = "": return True else : return False def update_board(board, row, col, current_player): board[row][col] = current_player def verify_entry(board, row, col): if board[row][col] = = " " : return True else : return False if row in range ( 0 , 3 ) and col in range ( 0 , 3 ): return True else : return False board = [[ " " , " " , " " ], [ " " , " " , " " ], [ " " , " " , " " ]] print_board(board) # prints an empty board current = None moves = 0 while moves < 9 and not check_winner(board, current): # game over? # play current = "X" if (current = = None or current = = "O" ) else "O" row, col = map ( int , input ( "Enter the move for " + current + ": " ).split( "," )) while not verify_entry(board, row, col): print ( "Wrong entry. Think again!" ) row, col = map ( int , input ( "Enter the move for " + current + ": " ).split( "," )) update_board(board, row, col, current) print_board(board) # prints the current board moves = moves + 1 if moves < 9 : print (current + " WON!" ) |