【发布时间】:2017-05-14 00:54:22
【问题描述】:
我试图强制用户在 python 中使用 try-except 输入一个数字,但它似乎没有效果。
while count>0:
count=count - 1
while (length != 8):
GTIN=input("Please enter a product code ")
length= len(str(GTIN))
if length!= 8:
print("That is not an eight digit number")
count=count + 1
while valid == False:
try:
GTIN/5
valid = True
except ValueError:
print("That is an invalid number")
count=count + 1
【问题讨论】:
标签: python python-3.x exception-handling user-input