2017-10-19 125 views
-4

我正在用下面提供的代码创建一个简单的Tic Tac Toe游戏。当我运行这个代码时,我得到一个无效的语法错误,True被突出显示。 While True循环不应该无限期地运行吗?基本while循环问题

# 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() 
+2

缩进在Python中很重要。 – nbro

回答

-1

您的While不应该大写。它应该是while。同时注意你的缩进,在块内没有看到任何内容。

+1

我很感谢downvote的反馈。 – MikeTheReader

0

虽然必须全部用小写:“while”。多数民众赞成在sintax错误

0

你要删除空行While True:move = input

之间的Python关心每一位压痕。另外,请确保while是小写字母。