1.要求
- 启动程序后,让用户输入工资,然后打印商品列表
- 允许用户genuine商品编号购买商品
- 用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒还有多少
- 可随时退出,退出时,打印已购买商品和余额
code:
1 #Author:Daniel 2 # -*- coding: utf-8 -*- 3 #time:2017.10.26-10:10 4 Commodity = [ 5 ('IPhone',6800), 6 ('Samsung',7000), 7 ('Huwei',10000), 8 ('Mi',11000), 9 ('vivo',12000), 10 ('NOKIA',15000), 11 ] 12 shopping_cart = [] 13 salary = input('Please enter your salary:') 14 if salary.isdigit(): 15 salary = int(salary) 16 while True: 17 for index,Commodity_list in enumerate(Commodity): 18 print(index,Commodity_list) 19 user_choice = input('Please enter the commodity number') 20 if user_choice.isdigit(): 21 user_choice = int(user_choice) 22 if user_choice < len(Commodity) and user_choice >= 0: 23 Phone = Commodity[user_choice] 24 if Phone[1] <= salary: 25 shopping_cart.append(Phone) 26 salary -= Phone[1] 27 print('