基本的while循环问题

时间:2017-10-19 18:40:35

标签: python loops while-loop

我正在使用下面提供的代码创建一个简单的Tic Tac Toe游戏。当我运行此代码时,我会收到无效的语法错误,并突出显示True。 While True循环不应该无限期地运行吗?

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

3 个答案:

答案 0 :(得分:0)

虽然必须全部为小写:"而"。那是sintax错误

答案 1 :(得分:0)

您要删除While True:move = input之间的空行

Python关心每一点缩进。另外,请确保while为小写。

答案 2 :(得分:-1)

您的While不应该大写。它应该是while。还要注意你的缩进,在阻挡时看不到任何内容。

相关问题