码迷,mamicode.com
首页 > 微信 > 详细

购物小程序(只用了list)

时间:2019-09-30 14:29:17      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:ase   lease   for   购物车   book   列表   while   input   hone   

#_author: FeiSir
#data: 2019/9/30

salary_of_shopper = int(input("Please input your salary:¥?"))
print("""
购物列表为:
1、iPhone 11 Pro 9999
2、iPhone 11 6299
3、华为手环 399
4、cup 59
5、pen 5
6、python book 85
""")
goods_list = ["无此商品","iPhone 11 Pro","iPhone 11","华为手环","cup ","pen","python book"]
price_goods_list = ["无此商品",9999,6299,399,59,5,85]
flag = True
buyed_list = []
money_shopper = salary_of_shopper
while flag:
index = int(input(‘Please input the index of goods you want:‘))
if price_goods_list[index] > money_shopper:
print("余额不足,¥%d"%(money_shopper - price_goods_list[index]))
flag_continue = input(‘是否继续购物(Y/N)‘)
if flag_continue == "N":
flag = False
else:
buyed_list.append(goods_list[index])
print("已将%s加入您的购物车,余额为¥%d" % (goods_list[index],money_shopper - price_goods_list[index]))
money_shopper -= price_goods_list[index]
flag_continue = input(‘是否继续购物(输入N退出,其余任意键继续购物)‘)
if flag_continue == "N":
flag = False
else:
the_number_buyed = len(buyed_list)
print("您购买的商品为:")
for i in range(the_number_buyed):
print("%d、%s:%d"%(i+1,buyed_list[i],price_goods_list[goods_list.index(buyed_list[i])]))
print("您的余额为:%d"%money_shopper)

购物小程序(只用了list)

标签:ase   lease   for   购物车   book   列表   while   input   hone   

原文地址:https://www.cnblogs.com/ofhanfei/p/11612540.html

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