自己写的import sysgoods=[[1,"milk",5],[2,"bike",800],[3,"iphone",5800]]bought=[]salary=int(input("input your salary:"))for i in goods: print(i)while 1: id=input("input the id of goods which you want to bug:") if id=="q": print("购买结束了") print("剩余金额:%s"%salary) for i in bought: print (i) sys.exit() id=int(id) if (salary-goods[id-1][2])>0: salary=salary-goods[id-1][2] bought.append(goods[id-1]) print(bought) print ("该商品购买成功") else: print("your balance is not enough:") 标准的:product_list=[ ('iphone',5800), ('mac pro',9800), ('bike',800), ('watch',10600), ('coffee',31)]shopping_list=[]salary=input("inpur your salary:")if salary.isdigit(): salary=int(salary) while 1: 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=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 salary is %s"%(p_item[0],salary)) else: print("你的余额不够了") else: print("product code %s is not exist!"%user_choice) elif user_choice=="q": print ("----shopping_list------") for p in shopping_list : print(p) print ("your current balance:",salary) exit() else: print ("invalid option")