Python学习笔记_购物车案例
goods_dic = { "iphone":6000, "ipad":3000, "T-shirt":100, "coffee":30, "car":500000, "macbook":10000, "mix4":9999, "pen":2 } goods_list = [] salary = int(input("请输入你的薪资(元):")) for k,v in goods_dic.items(): print(k,":",v,"元") while True: fav_goods = input("请输入你想购买的商品:") if salary >= goods_dic[fav_goods] : goods_list.append(fav_goods) print("商品已加入您的购物车") salary -= goods_dic[fav_goods] print("您的余额为:",salary) if salary == 0 or salary < goods_dic["pen"]: print("您的账户余额已不足") break continue else: print("您的余额不足以支付此商品") continue for i in goods_list: print("您购买的商品有:",i)