使用while检查输入是否在python3范围内

时间:2017-11-25 15:53:37

标签: python

初学者警报。这是我的tictactoe代码,当我试图检查玩家是否输入可玩值(1-9)时,我找不到问题。谢谢你的帮助。

   # the player now inserts input (coordinates of the field where he want his symbol written)
    print('Player', p, ', go! Enter the position that you want to play.')
    i = input()
    i = int(i) - 1

    while i in range(10,99):
        print('entered number does not match any position in the game, try again')
        break
    else:
        pass

1 个答案:

答案 0 :(得分:0)

if i not in range(1,10): 
  print("Invalid entry")

您应该使用if语句