sum=0
a1=""
shuru=input("请输入“手机”或“食物”:")
if shuru=="手机":
while True:
sp={"苹果7":5998,"小米":5298}
print(sp)
a=input("输入Buy进入结算,继续购买请输入物品名称:")
if a=="苹果7":
a=int(sp["苹果7"])
sum+=a
elif a=="小米":
a=int(sp["小米"])
sum+=a
elif a=="Buy":
print(sum)
else:
print ("输入有误!!!,请重新输入:")
elif shuru=="食物":
while True:
sp={"鸡蛋":5,"青菜":2}
print(sp)
a=input("输入Buy进入结算,继续购买请输入物品名称:")
if a=="鸡蛋":
a1 = "鸡蛋"
a=int(sp["鸡蛋"])
sum+=a
elif a=="青菜":
a1 = "青菜"
a=int(sp["青菜"])
sum+=a
elif a=="Buy":
print(sum)
else:
print ("输入有误!!!,请重新输入:")
else:
print ("输入有误!!!,请重新输入:")
![](https://img2018.cnblogs.com/blog/1657539/201905/1657539-20190522010154050-1108849504.png)