Enrollments closing soon for Post Graduate Certificate Program in Applied Data Science & AI By IIT Roorkee | 3 Seats Left

  Apply Now

Project- Game of Tic Tac Toe with Python

10 / 16

Tic Tac Toe with Python - Choose the winner

In this step we will write the logic to determine the winner. To achieve this, we will also list all possible combinations of 3 boxes that must be filled with the same symbol for a player to win.

INSTRUCTIONS
  • Write a function winner as shown below. This functions takes an argument called board:

    def <<your code goes here>>(<<your code goes here>>):
        WAYS_TO_WIN = ((0, 1, 2),
                       (3, 4, 5),
                       (6, 7, 8),
                       (0, 3, 6),
                       (1, 4, 7),
                       (2, 5, 8),
                       (0, 4, 8),
                       (2, 4, 6))
        for row in WAYS_TO_WIN:
            if board[row[0]] == board[row[1]] == board[row[2]] != EMPTY:
                winner = board[row[0]]
                return winner
        if EMPTY not in board:
            return TIE
        return None
    
See Answer

No hints are availble for this assesment


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

Loading comments...