prodcut_list=[ ('Iphone', 5800), ('Mac Pro', 9800), ('Bike', 800), ('Watch', 10600), ('Coffee', 31), ('Python Book', 49) ] shopping_list=[] salary=int(input('Input your salary:')) while True: for index,item in enumerate(prodcut_list): print(index,item) choice=input('>>>:选择要买嘛?>>>:') if choice.isdigit(): choice=int(choice) if choice<len(prodcut_list) and choice>=0: p_item=prodcut_list[choice] if p_item[1]<salary: salary-=p_item[1] shopping_list.append(p_item) print("Added %s into your shopping cart,your current balance is 33[32;1m%d 33[0m"%(p_item,salary)) else: print(" 33[42;1m你的余额只有%d,还买个球呀 33[0m"%salary) else: print("商品[%s]不存在"%choice) elif choice=='q': print('--------shoppinglist--------') for p in shopping_list: print(p) print("你的余额:",salary) exit() else: print('invalide option')