Je crée un jeu simple de Tic Tac Toe avec le code fourni ci-dessous. Lorsque j'exécute ce code, j'obtiens une erreur de syntaxe invalide avec True
en surbrillance. La boucle While True ne devrait-elle pas fonctionner indéfiniment?Numéro de boucle de base
# Tic-Tac-Toe
board = [1, 2, 3,
4, 5, 6,
7, 8, 9]
def printBoard():
print (board[0], '|', board[1], '|', board[2], '|')
print('- - - - - - ')
print (board[3], '|', board[4], '|', board[5], '|')
print('- - - - - - - -')
print (board[6], '|', board[7], '|', board[8], '|')
print('- - - - - - ')
While True:
move = input('Enter a number from the board?')
move = int(move)
if board[input] != 'x' or board[input] != '0':
board[input] = 'x'
else:
print('this spot is taken')
printBoard()
L'indentation est importante en Python. – nbro