第六天学习_购物车
li = [ {'name': '苹果','price':10}, {'name': '香蕉','price':20}, {'name': '西瓜','price':30}, ] shooping_car = {} # 把货物放在货架上 print('欢迎光临水果店') money = input('让我看看你的钱') if money.isdigit() and int(money) >0: while 1: for i,k in enumerate(li): print('序号{}, 商品{}, 价格{}'.format(i,k['name'],k['price'])) choose = input('请输入你要购买的商品的序号') if choose.isdigit() and int(choose) < len(li): num = input('请输入你要购买的数量') if num.isdigit(): if int(money) > li[int(choose)]['price'] * int(num): money = int(money) - li[int(choose)]['price'] * int(num) if li[int(choose)]['name'] in shooping_car: shooping_car[li[int(choose)]['name']] = shooping_car[li[int(choose)]['name']] + int(num) else: shooping_car[li[int(choose)]['name']] = int(num) print('购物车中的商品有{},你的余额为{}'.format(shooping_car,money)) else: print('回家拿钱去') break else: print('都说了是序号')