The check_win should return the variable and hence register as a win. Here's the code:
def game():
P1=Player()
P2=Player()
P1.name=input("Enter player 1's name: ")
P2.name=input("Enter player 2's name: ")
choice=random.randint(1,2)
if choice==1:
choosesign(P1,P2)
toss=1
else:
choosesign(P2,P1)
toss=2
gamewin=False
lastinput=" "
while (gamewin==False and is_full()==False):
for row in board:
print(row)
if lastinput==" " and toss==1:
inputsign(P1.sign)
lastinput=P1.sign
elif lastinput==" " and toss==2:
inputsign(P2.sign)
lastinput=P2.sign
elif lastinput==P1.sign:
inputsign(P2.sign)
lastinput=P2.sign
else:
inputsign(P1.sign)
lastinput=P1.sign
if check_win()==P1.sign:
print(f"{P1.name} Wins!")
gamewin=True
elif check_win()==P2.sign:
print(f"{P2.name} Wins!")
gamewin=True
if is_full()==True:
for row in board:
print(row)
print("Game ended on a draw!")
def check_win():
for row in board:
if row[0] == row[1] == row[2] and row[0] != " ":
return row[0]
for col in range(3):
if board[0][col]==board[1][col]==board[2][col]!=" ":
return [0][col]
if board[0][0] == board[1][1] == board[2][2] and board[0][0] != " ":
return board[0][0]
if board[0][2] == board[1][1] == board[2][0] and board[0][2] != " ":
return board[0][2]
else:
return False
game()