board = [' For I in range (9)]def Print_board (): Row_1 = ' | {}| {}| {}| '. Format (board[0], board[1], board[2]) row_2 = ' | {}| {}| {}| '. Format (board[3], board[4], board[5]) Row_3 = ' | {}| {}| {}| '. Format (Board[6], board[7], board[8]) print (' \ n ') print (row_1) print (row_2) print (row_3) print (' \ n ') def play Er_move (Icon): if icon = = ' X ': number = 1 elif icon = = ' O ': Number = 2 print (' Your turn player {}.‘. Format (number)) choice = Int (input (' Enter Your Move (1-9): '). Strip ()) if board[choice-1] = = ": Board[c HOICE-1] = icon Else:print (' \ n ') print (' That's space is taken! ') Def victory (Icon): if (board[0] = = icon and board[1] = = icon and board[2] = = icon) or (board[3] = = icon and boar D[4] = = icon and board[5] = = icon) or (board[6] = = icon and board[7] = = icon and board[8] = = icon) or (board [0] = = icon and board[3] = = icon and board[6] = = icon) or (board[1] = = icon and board[4] = = Icon And board[7] = = icon) or (board[2] = = icon and board[5] = = icon and board[8] = = icon) or (board[0] = = Icon an D board[4] = = icon and board[8] = = icon) or (board[2] = = icon and board[4] = = icon and board[6] = = icon): RE Turn true Else:return falsedef Game_is_draw (): If "not" Board:return true Else:ret Urn Falsewhile True:print_board () player_move (' x ') Print_board () If Victory (' X '): Print (' x wins! N icely done! ') Break Elif Game_is_draw (): Print (' It a draw! ') Break Player_move (' O ') if Victory (' O '): Print_board () print (' O wins! Nicely done! ') Break Elif Game_is_draw (): Print (' It a draw! ') Break
Learn Python 015:tic Tac Toe Game