GTIN = 0
while True:
try:
GTIN = int(input("input your gtin-8 number:"))
if len(str(GTIN)) == 8:
break
else:
print("make sure the length of the barcode is 8")
elif:
GTIN=(""):
GTIN = 0
while True:
GTIN = int(input("input your gtin-8 number:"))
if len(str(GTIN)) == 8:
print("OK: %s" % GTIN)
break
else:
print("make sure the length of the barcode is 8")
不能在
elif
之前使用else
。另一个问题是,必须在try
中添加except
。你知道吗编辑:您不需要elif。如果输入长度为8,则可以,否则请重试。你知道吗
Edit2:也不需要
try except
。 ps:如果您使用python 3相关问题 更多 >
编程相关推荐