product_list=[["iphone",6000],["苹果电脑",12000],["衣服",1000],["wine",500]] shopping_list=[] salary = input("请输入你的工资:") if salary.isdigit(): salary= int(salary) while True: for index,item in enumerate(product_list): # print(product_list.index(item),item) print(index,item) user_choice = input("选择要买吗:") #商品编号 if user_choice.isdigit(): user_choice = int(user_choice) if user_choice < len(product_list) and user_choice >=0: p_item=product_list[user_choice] if p_item[1] <= salary: #代表买的起商品 shopping_list.append(p_item)#把商品加入购物车列表 salary -=p_item[1] #当前扣除商品的余额 print("Added %s into shopping cart,your current balance is 33[31;1m%s 33[0m元" %(p_item,salary)) else: print("