码迷,mamicode.com
首页 > 编程语言 > 详细

python 购物车代码

时间:2017-09-14 23:39:56      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:python 购物车代码

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("穷逼","资产部足")


本文出自 “No lover” 博客,请务必保留此出处http://caojiaoyue.blog.51cto.com/11798573/1965219

python 购物车代码

标签:python 购物车代码

原文地址:http://caojiaoyue.blog.51cto.com/11798573/1965219

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!