检查用户输入是否为整数。如果没有,请再次重复

时间:2014-09-23 21:11:46

标签: python-3.x input

这是我目前的尝试

quantity = int(input("How many do you want?? "))
while (quantity < 1 or isinstance(quantity, int) == False):
    print("Error! Please enter a valid quantity value :)")
    quantity = int(input("How many do you want?? "))

我尝试将 == 替换为 ,但两者都返回以下错误

ValueError: invalid literal for int() with base 10: 'a'

我该怎么办?

0 个答案:

没有答案