代码拉取完成,页面将自动刷新
goods = [{"name": "电脑", "price": 1999},
{"name": "鼠标", "price": 10},
{"name": "游艇", "price": 20},
{"name": "美女", "price": 998},]
for i in range(len(goods)):
print(i + 1, goods[i]["name"], +goods[i]["price"])
je=input("请输入要充值的金额")
if je.isdigit() and int(je) > 0:
je = int(je)
print("充值成功,当前金额%d" % je)
else:
print("请正确输入")
gwc={}
shopping_money=0
while True:
sp = input("输入选择的商品序号[1-4],N-n(结算)/输入Q或者q退出程序")
if sp.isdigit() and 0 < int(sp) < len(goods) + 1:
print(int(sp), goods[int(sp) - 1]["name"], goods[int(sp) - 1]["price"])
# gwc[int(sp)] = {goods[int(sp) - 1]["name"], goods[int(sp) - 1]["price"]}
# print(gwc)
shoppug_name = goods[int(sp)-1]["name"] # 获取到用户序号对应的商品名字
shoppug_price = goods[int(sp)-1]["price"] #获取到用户序号对应的商品
# print(shoppug_name)
# print(shoppug_price)
if goods[int(sp)-1]["name"] in gwc:
gwc[shoppug_name]["num"] += 1
else:
gwc[shoppug_name] = {"money":shoppug_price,"num":1}
# print(gwc)
elif sp.upper() == "N":
shopping_money = 0
for i in gwc:
print(f"购买的商品:{i} 单价:{gwc[i]['money']} 数量:{gwc[i]['num']}")
shopping_money += gwc[i]['money'] * gwc[i]['num'] #总价
print(shopping_money)
if je - shopping_money >= 0:
je = je - shopping_money
print(f"结算成功 当前剩余金额:{je}")
elif je - shopping_money < 0:
xuanze = input(f"当前余额不足请选择:1: 充值 2: 选择删除商品")
if xuanze == "1":
xuanzecz = input("请输入需要充值的金额")
xuanzecz = int(xuanzecz)
je += xuanzecz
print(f"充值成功当前余额剩余{je}")
elif xuanze == "2":
for i in gwc:
print(f"购买的商品:{i} 单价:{gwc[i]['money']} 数量:{gwc[i]['num']}")
shanchu = input("请输入需要删除的商品")
if shanchu in gwc:
if gwc[shanchu]["num"] == 1:
del gwc[shanchu]
else:
gwc[shanchu]["num"] -= 1
else:
print("请正确输入")
else:
print("请正确输入")
elif sp.upper() == "Q":
break
else:
print("请正确输入")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。