在井字游戏中,无效动作的循环也在减少有效动作
In tic-tac-toe game while loop for invalid moves is declining valid moves too
[游戏将显示为九个方块,行列用数字标示,方块坐标为组合;例如:11(第一列,第一行),12(第一列,第二行),13、21、22 等,直到 33]
我的显示器坏了,只是想不通这一个问题。
以下是我接受动作的代码:
askformovestr = "Turn: X. Please enter the coordinates for the square in which you wish to drop your piece, with column number followed by row number(e.g. 11 drops to top left square, 12 to the square below it, 23 to the square in the third row, second column, etc., etc.): "
def askformove():
inmove = int(input(askformovestr))
while inmove is not 11 or 12 or 13 or 21 or 22 or 23 or 31 or 32 or 33:
print("Invalid input, sorry. Please try again.")
inmove = int((input("Turn: X. Please enter the coordinates for the square in which you wish to drop your piece(e.g. 1B, 2C, 3A, etc.): ")))
askformove()
也许可以这样:
while inmove is not 11 or 12 or 13 or 21 or 22 or 23 or 31 or 32 or 33:
试试这个:
while (inmove != 11 or inmove != 12 or inmove != 13 or inmove != 21 or inmove != 22 or
inmove != 23 or inmove != 31 or inmove != 32 or inmove != 33):
[游戏将显示为九个方块,行列用数字标示,方块坐标为组合;例如:11(第一列,第一行),12(第一列,第二行),13、21、22 等,直到 33] 我的显示器坏了,只是想不通这一个问题。
以下是我接受动作的代码:
askformovestr = "Turn: X. Please enter the coordinates for the square in which you wish to drop your piece, with column number followed by row number(e.g. 11 drops to top left square, 12 to the square below it, 23 to the square in the third row, second column, etc., etc.): "
def askformove():
inmove = int(input(askformovestr))
while inmove is not 11 or 12 or 13 or 21 or 22 or 23 or 31 or 32 or 33:
print("Invalid input, sorry. Please try again.")
inmove = int((input("Turn: X. Please enter the coordinates for the square in which you wish to drop your piece(e.g. 1B, 2C, 3A, etc.): ")))
askformove()
也许可以这样:
while inmove is not 11 or 12 or 13 or 21 or 22 or 23 or 31 or 32 or 33:
试试这个:
while (inmove != 11 or inmove != 12 or inmove != 13 or inmove != 21 or inmove != 22 or
inmove != 23 or inmove != 31 or inmove != 32 or inmove != 33):