购物车的流程是真的学了好几遍视频课才把代码跟着老师的讲解抄了一遍啊
product_list=[ ("Iphone",5800), ("Mac Pro",10800), ("Bike",800), ("Watch",10600), ("Coffee",31), ("Alex Python",120), ] # 产品列表 shopping_list=[] # 购物车列表 salary = input("Input your salary:") #输入工资 if salary.isdigit(): # 判断工资是不是数字型 salary = int(salary) # 工资转化成数字型 while True: '''for item in product_list: print(product_list.index(item),item)''' # 取商品编号和商品 方法一 for index,item in enumerate(product_list): # 取商品编号和商品 方法二 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,you current balance is 33[31;1m%s 33[0m"%(p_item,salary)) # 商品加入购物车,高亮显示余额(33红色,32绿色,[31字体高亮) else: print("