python 购物车代码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 购物车代码

Python简单的购物车小代码

常用python日期日志获取内容循环的代码片段

python [代码片段]一些有趣的代码#sort

Python 向 Postman 请求代码片段

python 有用的Python代码片段