购物车练习
buy_price = [5800,9000,200,300,500]
buy_shoop = ["iphone6s","mac book","coffee","python book","bicyle"]
print("《购物车程序》")
print("您的余额:5000")
print("商品列表:",
"""
1. iphone6s ¥5800
2. mac book ¥9000
3. coffee ¥200
4. python book ¥300
5. bicyle ¥500
""")
user_buy_shoop = []
user_buy_price = 5000
while True:
user_buy_id = input("输入您要购买商品的序号或输入quit退出程序>>>:")
if user_buy_id.isdigit() and 0 < int(user_buy_id) < 6:
user_buy_id = int(user_buy_id) - 1
if buy_price[user_buy_id] > user_buy_price:
print("余额不足", 5000 - (buy_price[user_buy_id]))
else:
user_buy_shoop.append(buy_shoop[user_buy_id])
user_buy_price = user_buy_price - buy_price[user_buy_id]
print("已加入 %s 到你的购物车, 当前余额: %d " % (buy_shoop[user_buy_id], user_buy_price))
elif user_buy_id == 'quit':
print("您已购买以下商品:")
for i in user_buy_shoop:
print(i)
print("您的余额为: %d" % user_buy_price)
print("欢迎下次光临!")
break
else:
print("请输入正确内容!")