jiage = {} caojiaoyue = [ { "name": "奥迪", "price": 10000}, { "name": "摩托车", "price": 1000}, { "name": "自行车", "price": 100}, { "name": "玩具车", "price": 10}, ] for a in caojiaoyue: print(a["name"],a["price"]) zc = int(input("请输入资产:")) while True: sp = input("请输入商品/按Y结算:") if sp == "y" or sp == "Y": break for i in caojiaoyue: if sp == i["name"]: if sp in jiage.keys(): jiage[sp]["数量"] = jiage[sp]["数量"] +1 else: jiage[sp] = { "商品":i["name"],"价格":i["price"],"数量":1} else: print("商品错误") break zongjia = 0 print(jiage) for i in jiage.values(): zongjia = i["价格"] * i["数量"] + zongjia if zc >= zongjia: print("购买成功") else: print("穷逼","资产部足")