1 #-*- coding:utf-8 *-* 2 salary = 5000 3 4 shop_list = [('iphone',9000),('mac book',10000),('python book',90),('coffee',32), 5 ('bicycle',1500)] 6 7 money = input("请输入您的现金总数:") 8 money = int(money) 9 have_buy_commodity = [] 10 while True: 11 for i, v in enumerate(shop_list, 1): 12 print(i, v) 13 14 query_buy_shop = input("请输入要购买的商品编号,q[退出]:") 15 16 if query_buy_shop.isdigit(): 17 query_buy_shop = int(query_buy_shop) 18 19 if query_buy_shop >=1 and query_buy_shop <=5: 20 spend_money = shop_list[query_buy_shop-1] 21 buy_commodity = shop_list[query_buy_shop-1][0] 22 money = money - spend_money[1] 23 have_buy_commodity.append(buy_commodity) 24 if money < 0: 25 print("您的余额不足!") 26 print('--------Shop List--------') 27 print(have_buy_commodity) 28 print('--------------------------') 29 break 30 else: 31 print("您的余额为%s元!"%money) 32 33 34 35 36 37 elif query_buy_shop == 'q': 38 print("退出成功!") 39 # print('--------Shop List--------') 40 # print(have_buy_commodity) 41 # print('--------------------------') 42 43 else: 44 print("输入的字符非法,请重新选择")