1 #_author_: edison 2 #date: 2017/8/8 3 salary = int(input('please input your salary:')) 4 flag = True 5 a = [1,2,3,4,5] 6 b = ['iphone7','mac pro','coffee','bicycle','shoes'] 7 c = [5600,10988,32,988,699] 8 product = [] 9 for i in range(5): 10 print(a[i],b[i],c[i]) 11 while flag: 12 number = int(input('输入你想购买商品的号数:')) # 转化成整形 13 for i in range(5): 14 if a[i] == number: 15 price_spread = salary-c[i] 16 if price_spread >= 0: 17 print(b[i],'也加入你的购物车'+'当前余额:',price_spread) 18 product.append(i) 19 sentence = input('go on or quit?') 20 if sentence == 'quit': 21 flag = False 22 print('你购买了以下产品:') 23 cost_money = 0 24 for i in product: 25 print('商品:',b[i],'价格:',c[i]) 26 cost_money = cost_money + c[i] 27 print('你本次消费:',cost_money) 28 else: 29 salary = price_spread 30 else: 31 print('余额不足:') 32 # for i in product: 33 # cost_money = 0 34 # cost_money = cost_money + c[i] 35 # print('你本次消费:',cost_money) 36 print('你的余额为:',price_spread,'欢迎下次光临!')