Registrations Closing Soon for DevOps Certification Training by CloudxLab | Registrations Closing in

  Enroll Now

Tic Tac Toe with Python - Bring it all together

Now we will write the main function that does the following:

  1. Displays instructions using the display_instructions function
  2. Checks which player will go first and switches the turn accordingly
  3. Initializes and displays the board
  4. Till the time there is a winner, it keeps playing
  5. Once we have a winner (or a draw), it congratulates the winner

And all of these are done by bringing together all the functions that we created so far.

INSTRUCTIONS
  • Write the main function as shown below:

    def main():
        display_instructions()
        computer, human = pieces()
        turn = X
        board = new_board()
        display_board(board)
    
        while not winner(board):
            if turn == human:
                move = human_move(board, human)
                board[move] = human
            else:
                move = computer_move(board, computer, human)
                board[move] = computer
            display_board(board)
            turn = next_turn(turn)
    
        the_winner = winner(board)
        congrat_winner(the_winner, computer, human)
    

No hints are availble for this assesment

Answer is not availble for this assesment


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...