作业
2019-05-22 11:14 Memory浅梦 阅读(194) 评论(0) 编辑 收藏 举报BUY = [["iphone", 5888],
["1+7PRO", 4888],
["MEIZU16", 2999],
["MI6", 2499],
["HUAWEIP30", 3999],
["IQOO", 2999]]
xz = {}
hf = 0
while True:
choice = input("输入你所选择的商品编号>>:").strip()
if choice.isdigit():
choice = int(choice)
if choice < len(BUY) and choice >= 0:
product = BUY[choice]
if product[0] in xz:
xz[product[0]][1] += 1
else:
xz[product[0]] = [product[1], 1]
print("目前你的购物车", xz)
elif choice == "buy":
print("---------你购买的商品如下---------")
print("id", "\t", "商品", "\t", "数量", "\t", "单价", "\t", "总价")
id_counter = 1
for key in xz:
print(id_counter, "\t",
key, "\t",
xz[key][1], "\t\t",
xz[key][0], "\t",
xz[key][1] * xz[key][0])
id_counter += 1
hf+= xz[key][1] * xz[key][0]
print("总计价格为", hf)
print("结束")
break
else:
print("请输入正确的编号!")