Question: Python Question => Why I got the anwser : The winner is Nobody? The answer should be the winner is player 1. ------------------- My Code

Python Question => Why I got the anwser: The winner is Nobody?

The answer should be the winner is player 1.

------------------- My Code Below -----------------------

board = [[1, 0, 0], [2, 1, 0], [2, 2, 1]]

winners = {0:'Nobody', 1:'Player1', 2:'Player2'}

def __rule__(): for i in range(0, 3): # horizontal equal if board[0] == [i, i, i] or board [1] == [i, i, i] or board[2] == [i, i, i]: return winners[i] # vertical first column equal elif board[0][0] == board[1][0] == board[2][0]: return winners[i] # vertical second column euqal elif board[0][1] == board[1][1] == board[2][1]: return winners[i] # vertical third column equal elif board[0][2] == board[1][2] == board[2][2]: return winners[i] # diagonal elif board[0][0] == board[1][1] == board[2][2]: return winners[i] # diagonal elif board[0][2] == board[1][1] == board[2][0]: return winners[i] # draw else: return winners[0]

winner = __rule__() print('The winner is %s' %winner)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!