day5 模拟购物车程序

 1 #__author__: Administrator
 2 #__date__: 2018/7/11
 3 
 4 print('''
 5 ======本公司退出以下产品=======
 6 1.bicycle---------------700
 7 2.iphone---------------4500
 8 3.coffee-----------------30
 9 4.cat------------------9999
10 5.sunglasses-------------70
11 ''')
12 
13 
14 salay = int(input("请输入您的钱包:"))
15 print("您的钱包目前有:%d" % salay)
16 shopping_list = ["nothing", "bicycle", "iphone", "coffee", "cat", "sunglasses" ]  #shopping_list 商品名字列表
17 price = [0, 700, 4500, 30, 9999, 70]                     #price[] 价格表
18 shopping_cart_list = []                                  #shopping_list 购物车
19 choose_time = 0                                          #choose_time 选择的次数
20 last_money = salay                                       #last_money 余额
21 
22 while last_money > 0:
23     print('''
24     ======本公司推出以下产品=======
25     1.bicycle---------------700
26     2.iphone---------------4500
27     3.coffee-----------------30
28     4.cat------------------9999
29     5.sunglasses-------------70
30     ''')
31     choose_num = int(input("请输入您要购买的商品标号:  "))  #choose_num 选择的商品编号
32     choose_goods= shopping_list[choose_num]                  #choose_goods 选择的商品名字
33     print("商品 %s 已经加入您的购物车." %choose_goods)
34 
35     choose_time += 1                                         #选择次数+1
36     shopping_cart_list.append(choose_goods)                  #将商品加入购物车
37 
38                                #结算次数与选择次数相同
39     print("-----您的购物车有以下产品-----")                 #显示购物车
40 
41     shopping_cart_num = 0         # shopping_cart_num 购物车内的商品个数 ,应等同于购物车内元素个数
42     if shopping_cart_num < int(len(shopping_cart_list)) :
43         print("%d . %s" %(choose_time,shopping_cart_list[choose_time - 1]))
44         print(shopping_cart_list)
45         shopping_cart_num += 1
46     settlment_time = choose_time
47     if  settlment_time > 0 :                                  #循环打印商品的名字
48         last_money = last_money - price[choose_num]
49         print("您的余额为:%d" % last_money)
50         settlment_time -= 1
51 else :
52      print("你的钱包已经空了,滚滚滚,发了工资再来吧!")

 

转载于:https://www.cnblogs.com/shijieli/p/9679955.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值