# -*- coding:utf-8 -*- # __author__ : poetl # date: 2017/12/26 salary = int(input("Please input your salary:")) balance = salary shop_list = [5800, 1500, 9000, 32, 80] shop_name = ["iphone6s", "bicyle", "macbook", "coffee", "python_book"] iphone6s = 5800 bicyle = 1500 macbook = 9000 coffee = 32 python_book = 80 all = [] msg = ''' 余额: %d -------------- list: 1.iphone6s:%d 2.bicyle:%d 3.macbook:%d 4.coffee:%d 5.python_book:%d -------------- ''' % (salary, iphone6s, bicyle, macbook, coffee, python_book) print(msg) try: while True: input_code_1 = input("选择商品 退出输入quit:") if input_code_1 != "quit": input_code = int(input_code_1) - 1 price = shop_list[input_code] if balance < price: print("您的余额不足",balance - price) else: balance = balance - price print("余额为%d" % balance) all.append(shop_name[input_code]) print(all) else: print('购买清单 ',all) print('余额 %d, 欢迎下次光临' % balance) break except IndexError: print("你在干嘛!")