需要重复声明

时间:2017-03-19 20:11:49

标签: python

我在这里遇到了一些问题,我的代码需要询问用户他们的8 GTIN号码,在输入他们的8 GTIN号后,它应该显示他们的GTIN号码产品的正确描述并需要告诉用户他们喜欢的产品中有多少,在输入金额后,应显示总费用并再次询问GTIN号码,直到用户输入“结帐”

fj = "plain brackers which are £0.50 each, how many of them would you like to buy?"
fd = "product not found "
sa = "100mm bolts, £0.20 each, how many you want to buy?"
de = "L-shaped brackets, £1.20 each, how many would you like to buy?"
aer = int(input("Please type in your 8 digit code"))
if aer == 34512340:
    dre = int(input(fj))
    ret = (dre*0.50)
    print("Your amount is £",ret)
elif aer == 98981236:
    print(fd)
elif aer == 56756777:
    ght = int(input(sa))
    rer = (ght*0.20)
    print("Your amount is £",rer)
elif aer == 90673412:
    dwe = int(input(de))
    ret = (dwe*1.20)
    print("Your amount is £",ret)
else:
    print("Error")

然而问题是,在显示总和之后,它不会要求我再次输入它应该做的GTIN号码。

1 个答案:

答案 0 :(得分:0)

您只需要一个while循环。听起来你不想让它真诚地打破。你的第二个while循环随后没有要求输入金额,所以也许这就是你所指的那个?

无论如何,我会使用if-else结构来检查输入。

try