I am building a tic tac toe game in python. it is very unpolished at this stage, but functional. my issue is this - I made a function to check for winners. it looks like this:
def check_winner(spots):
if spots[1] == spots[2] == spots[3]:
return True
print("Winner found!")
if spots[4] == spots[5] == spots[6]:
return True
print("Winner found!")
if spots[7] == spots[8] == spots[9]:
return True
print("Winner found!")
if spots[1] == spots[4] == spots[7]:
return True
print("Winner found!")
if spots[3] == spots[6] == spots[9]:
return True
print("Winner found!")
if spots[1] == spots[5] == spots[9]:
return True
print("Diagonal winner found!")
if spots[3] == spots[5] == spots[7]:
return True
print("Diagonal winner found!")
I have my check_winner function in my while loop for the game below. However, when a winner is found on the board, and the function returns true, the "winner found" statement is not being printed at all. why is this?:
while winner == False:
if Turns % 2:
Letter = 'X'
else:
Letter = 'O'
print_board(spots)
if check_winner(spots) == True:
break