老男孩购物车程序
1 salary = input('您的工资是:') 2 item_list = [ 3 ('iphone',5800), 4 ('pc',12325), 5 ('watch',7000), 6 ('book',38), 7 ('pen',5), 8 ('game',1000) 9 ] 10 buy_list=[] 11 print(type(salary)) 12 while True: 13 if salary.isdigit(): 14 salary = int(salary) 15 break 16 else: 17 salary = input('请输入正确的工资,您的工资是:') 18 19 while True: 20 # print(salary) 21 22 # print(type(salary)) 23 # print(salary) 24 for index, item in enumerate(item_list): 25 print(index, item) 26 user_choice = input('要买什么>>>:') 27 if user_choice.isdigit(): 28 user_choice = int(user_choice) 29 if user_choice < len(item_list) and user_choice >= 0: 30 p_item = item_list[user_choice] 31 if salary >= p_item[1]: 32 salary -= p_item[1] 33 buy_list.append(p_item) 34 print('余额:',salary) 35 else: 36 print('没钱了') 37 else: 38 print('输入正确产品编号:') 39 elif user_choice == 'q': 40 print('-------------shopping list--------------') 41 for i in buy_list: 42 print(i) 43 print('还剩下:',salary) 44 exit() 45 else: 46 print("输入正确商品")