li =[ { "name":"苹果","price":10}, { "name":"香蕉","price":20}, { "name":"木瓜","price":30},]#把货物放在货架上shopping_car={}print("欢迎光临田园水果店")money = input("请输入你的现金 : ")while 1: if money.isdigit() and int(money)>0: for i ,k in enumerate(li): print('序号{},商品{},price{}'.format(i,k['name'],k['price'])) choose = input ("请输入你要购买的商品序号") if choose.isdigit() and int(choose)li[int(choose)]['price']*int(num): money =int(money)-li[int(choose)]['price']*int(num) if li[int(choose)]['name'] in shopping_car: shopping_car[li[int(choose)]['name']]=shopping_car[li[int(choose)]['name']] + int(num) else: shopping_car[li[int(choose)]['name']]=int(num) print("购物车中的商品有{},您的余额为{}".format (shopping_car,money)) else: print("您的余额不足!") break else: print('填序号!')