samedi 19 juin 2021

Why isn't the "and" operator working properly in my game? [duplicate]

This program is for a tic tac toe game and I designed a function to check for when either X or O would win. The if statement is practically the same just for different lines but every time I put in a certain position in the board it will print "X wins" despite not having all three X's, which makes me think the and operator isn't working.

Does anybody have any input as to what could be happening?

if ("X" in (board[0][0] and board[2][0] and board[4][0])) or ("X" in (board[0][0] and board[0][2] and board[0][4])):
    print("X wins")

board = [[" ", "|" ," ", "|" ," "],
         ["-", "-", "-", "-", "-"],
         [" ", "|" ," ", "|" ," "],
         ["-", "-", "-", "-", "-"],
         [" ", "|" ," ", "|" ," "],
         ["-", "-", "-", "-", "-"]]

Aucun commentaire:

Enregistrer un commentaire