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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started