标签:while mac pro att product car and *** choice sed
product_list =[(‘Iphonex‘,8300), (‘Moto‘,6900), (‘Mac Pro‘,18900), (‘Latte‘,30), (‘Mix‘,3999)] yourSalary = input("Please print your Salary:") shopping_list = [] #添加购物车 if yourSalary.isdigit(): yourSalary = int(yourSalary) while True: ‘‘‘ 1.列出商品编号,还有商品 for item in product_list: print(product_list.index(item)+1,item) ‘‘‘ for index,item in enumerate(product_list): #枚举方式 print(index+1,item) your_choice = input("选择要买的商品>>>:") if your_choice.isdigit(): your_choice = int(your_choice)-1 if your_choice < len(product_list) and your_choice >= 0:#判断选择是否在范围内 p_item = product_list[your_choice] #选出选择的商品 if p_item[1]<= yourSalary : #买得起 shopping_list.append(p_item)#添加到购物车 yourSalary -=p_item[1] #从卡里扣钱 print("Added %s into shopping car,your balance is " "\033[31;1m%s\033[0m" %(p_item,yourSalary)) # 31--设置字体颜色 else: print("\033[41;1mYour last money just %s,go working!\033[0m" %(yourSalary))# %s相当于占位符,给%用 41--设置字体背景颜色 # \033[41;1m************************\033[0m else: print ("Wrong written!") elif your_choice == ‘q‘: print("------------shopping list-------------") for p in shopping_list: print(p) print("your Salary:",yourSalary) exit() else: print ("invalid") else: print("Wrong Writen!")
标签:while mac pro att product car and *** choice sed
原文地址:http://www.cnblogs.com/PurpleSun/p/7563435.html