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------------------999910 5.sunglasses-------------7011 ''')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---------------70026 2.iphone---------------450027 3.coffee-----------------3028 4.cat------------------999929 5.sunglasses-------------7030 ''')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 #选择次数+136 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 += 146 settlment_time = choose_time47 if settlment_time > 0 : #循环打印商品的名字48 last_money = last_money - price[choose_num]49 print("您的余额为:%d" % last_money)50 settlment_time -= 151 else :52 print("你的钱包已经空了,滚滚滚,发了工资再来吧!")