I'm new to python and I tried to make if statements and they didn't work for some reason. My problem is in xwins() and owins() They didn't return True even if the conditions were met. I'm not sure how to fix it. If someone has another way to do the same thing it will be greatly appreciated I'd be glad if someone would tell me how to fix the code Thanks in advance!
board = [0, 0, 0], [0, 0, 0], [0, 0, 0]
def print_board():
print(" ", "A", "", "B", "", "C")
count = 0
for i in board:
print(count, i)
count += 1
def updateboard(x, y, z):
print(" ", "A", "", "B", "", "C")
count = 0
board[x][y] = z
for i in board:
print(count, i)
count += 1
def pick_place():
z = ""
while xwins() or owins() != True:
while not(z == "X" or z == "O"):
z = input("Enter X or O\n")
x = int(input("Enter Row\n"))
y = input("Enter Column\n")
if z == "O":
x, y = letternumber(x, y)
updateboard(x, y, "O")
elif z == "X" or "x":
x, y = letternumber(x, y)
updateboard(x, y, "X")
def xwins():
if not(board[0][0] != "X") and not(board[0][1] != "X") and not(board[0][2] != "X"):
return True
elif board[1][0] == "X" and board[1][1] == "X" and board[1][2] == "X":
return True
elif board[2][0] == "X" and board[2][1] == "X" and board[2][2] == "X":
return True
elif board[0][0] == "X" and board[1][1] == "X" and board[2][2] == "X":
return True
elif board[0][2] == "X" and board[1][1] == "X" and board[2][0] == "X":
return True
def owins():
if board[0][0] == "O" and board[0][1] == "O" and board[0][2] == "O":
return True
elif board[1][0] == "O" and board[1][1] == "O" and board[1][2] == "O":
return True
elif board[2][0] == "O" and board[2][1] == "O" and board[2][2] == "O":
return True
elif board[0][0] == "O" and board[1][1] == "O" and board[2][2] == "O":
return True
elif board[0][2] == "O" and board[1][1] == "O" and board[2][0] == "O":
return True
def letternumber(x, y):
if x == 0:
x = 0
elif x == 1:
x = 1
elif x == 2:
x = 2
if y == "A":
y = 0
elif y == "B":
y = 1
elif y == "C":
y = 2
return x, y
Aucun commentaire:
Enregistrer un commentaire