1 # 购物商城 2 # 商品展示,价格 3 # 购买商品,加入购物车,一直往里面加 4 # 付款,你有4000元,钱不够,就撤单。 5 6 items = {‘cpu‘: ‘800‘, ‘主板‘: ‘800‘, ‘机箱‘: ‘300‘, ‘显卡‘: ‘2000‘, ‘键盘‘: ‘800‘, ‘耳机‘: ‘300‘} 7 Cost_list = items.items() 8 print(Cost_list) 9 Cost_items = {} 10 while True: 11 item_name = input(‘请输入你想要买的商品名字,点击Q退出购物车‘) 12 if item_name != ‘Q‘: 13 if item_name in Cost_items.keys(): 14 Cost_items[item_name].append(items[item_name]) 15 else: 16 Cost_items[item_name] = items[item_name] 17 else: 18 break 19 print(‘您购物完毕,以下是您的购物清单‘) 20 print(Cost_items) 21 sum_items = 0 22 for k in Cost_items: 23 sum_items += int(Cost_items[k]) 24 if sum_items > 4000: 25 print(‘余额超标%s‘%[sum_items-4000]) 26 while True: 27 remove_item = input(‘请输入你要拿走的商品,按Q退出撤单系统‘) 28 sum_items -= int(Cost_items[remove_item]) 29 pop_item = Cost_items.pop(remove_item) 30 print(‘现在的金额是%s‘%[sum_items]) 31 if sum_items < 4000: 32 Input = input(‘您消费金额已经低于你的所有的钱,还想继续撤单吗,Y/N‘) 33 if Input == ‘Y‘: 34 continue 35 else: 36 break 37 else: 38 continue 39 print(‘欢迎下次光临,您的消费金额是%s,现金还是刷卡‘%[sum_items]) 40 else: 41 print(‘欢迎下次光临,您的消费金额是%s,现金还是刷卡‘%[sum_items])
时间: 2024-10-03 06:20:40