Python 官方文档:入门教程 => 点击学习
jiage = {}caojiaoyue = [{"name": "奥迪", "price": 10000},{"name": "摩托车", "price": 1000},{"name": "自行车", "price": 100},{"na
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("穷逼","资产部足")
--结束END--
本文标题: python 购物车代码
本文链接: https://lsjlt.com/news/182797.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0