Python3实现购物车程序
程序员文章站
2022-04-04 15:28:09
#!usr/bin/env python # -*- coding:utf-8 -*- assets = 0 li = input("请输入总资产:") assets = li car_list = [] #用户选择商品存放购物列表 goods = [ {"name": "电脑", "price":... ......
#!usr/bin/env python # -*- coding:utf-8 -*- assets = 0 li = input("请输入总资产:") assets = li car_list = [] #用户选择商品存放购物列表 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"]) #print(i) while True: i2 = input("请选择商品(Y/y结算):") if i2.lower() == "y": break for j in goods: if j["name"] == i2: car_list.append(j) #结算 all_price = 0 for itemd in car_list: p = itemd["price"] all_price = all_price + p print(assets,all_price) if int(all_price) > int(assets): print("穷逼") else: print("购买成功!")
下一篇: UE4【C++】子弹伤害系统使用