我正在尝试验证输入,以便它必须是整数。我已经验证了输入,因此它必须在一定范围内,但是如果他们输入字母“b”,例如,就会出现错误,显示为“ValueError:invalid literl for int() with base 10”。如果值不是整数,我希望在 else 部分中显示相同的消息。我已经在网上搜索了一段时间,无法弄清楚如何验证输入,所以它必须是一个整数。
Minutes=int(input("How long do you want the interval between each stretch to be?\nIndicate a number in minutes between 5 and 60\n\nAfter the minutes specified, a window with suggested stretches will appear\n--> "))
y=1 而 y==1:
if Minutes in range (4,61):
TimeMinute (Minutes) #(Minutes needs to be multiplied by 60 to make it into minutes) Minutes is currently in the unit of seconds
y=0
else:
Minutes=int(input ("Error. You need to enter a number between 5 and 60.\nHow long do you want the interval between each stretch to be?\nIndicate a number in minutes between 5 and 60\nAfter the minutes specified, a window with suggested stretches will appear\n--> "))