购物小程序(只用了list)
Posted ofhanfei
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了购物小程序(只用了list)相关的知识,希望对你有一定的参考价值。
#_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)的主要内容,如果未能解决你的问题,请参考以下文章