简易购物车的程序
1 # 输入工资: 2 # 出现列表选购商品 3 # 0.咖啡:223 4 # 1.碳酸饮料 :105 5 # 2.茶饮:59 6 # 3.奶制品:33 7 # 4.矿泉水:18 8 # 输入商品编号 9 # 打印商品,余额 10 # 提示是否继续编号购买或者输入quit退出 11 # 继续输入编号购买打印全部商品名称和余额 12 salary=int(input('Input your salary:')) 13 mylist=[] 14 remaining=salary 15 if remaining>=0: 16 print(''' 可选购商品 17 0.咖啡:223 18 1.碳酸饮料 :105 19 2.茶饮:59 20 3.奶制品:33 21 4.矿泉水:18 22 ''') 23 while True: 24 choice=['咖啡','碳酸饮料','茶饮','奶制品','矿泉水'] 25 price=['223','105','59','33','18'] 26 number=input('输入清单中的编号或者输入‘quit’退出:') 27 if number=='quit': 28 exit(mylist) 29 if 0 <= int(number) <= 4: 30 if remaining - int(price[int(number)]) >= 0: 31 mylist.append(choice[int(number)]) 32 remaining = remaining - int(price[int(number)]) 33 print(mylist,'\t','余额:',remaining) 34 else: 35 print('余额不足',mylist,'\t','余额:',remaining) 36 else:print('超出可选范围') 37 else:exit('工资不能为负数')