标签:coding dict python 购物 bre assets item 需要 odi
#!usr/bin/env python # -*- coding:utf-8 -*- assets = 0 li = input("请输入总资产:") assets = li goods = [ {"name": "电脑", "price": 2000}, {"name": "游艇", "price": 3000}, {"name": "手机", "price": 1900}, {"name": "美女", "price": 4000}, {"name": "手表", "price": 1000}, ] for i in goods: print(i["name"],i["price"]) car_dict = {} while True: i2 = input("请选择您需要购买的商品:") if i2.lower() == "y": break for itemd in goods: if itemd["name"] == i2: name = itemd["name"] if name in car_dict.keys(): car_dict[name]["num"] = car_dict[name]["num"] + 1 else: car_dict[name] = {"num": 1,"single_price": itemd["price"]} print(car_dict) #结算 car_all_price = 0 for k,v in car_dict.items(): n = v["single_price"] m = v["num"] car_all_price_sum = n * m car_all_price = car_all_price + car_all_price_sum print(assets,car_all_price) if int(car_all_price) > int(assets): print("穷鬼!") else: print("购买成功,咱回家!")
标签:coding dict python 购物 bre assets item 需要 odi
原文地址:https://www.cnblogs.com/mengl950012/p/9132495.html