标签:strip end ping src com product pen 序号 menu
#全部小代码在此 product_list = [[‘Iphone7‘,5800], [‘Coffee‘,30], [‘疙瘩汤‘,10], [‘Python Book‘,99], [‘Bike‘,199], [‘ViVo X9‘,2499] ] shopping_cart = [] salary = int(input("input your salary:")) while True: menu = u‘‘‘ ------- Good Shopping --------- \033[32;1m 1. 输入序号买商品进入购物车 2. 输入q打印购物清单退出 \033[0m‘‘‘ print(menu) index = 0 for product in product_list: print(index,product) index +=1 choice = input(">>").strip() if choice.isdigit(): #判断是否为数字 choice = int(choice) if choice >= 0 and choice < len(product_list):#商品存在 product = product_list[choice]#取到商品 if product[1] <= salary:#判断能否买得起 shopping_cart.append(product)#加入购物车 salary -= product[1]#扣钱 print("added product "+ product[0] + "into shopping cart,your current balance"+ str(salary)) print("现在的余额为 %d 元" % salary) #print("jia ge shi " + product[haproxy.conf] + "yuan") else: print("买不起,穷逼!产品价格是"+str(product)[1]+"你还差钱"+str(product[1]-salary)+"钱") else: print("商品不存在") elif choice == "q": print("----已购买商品列表-----") print("id 商品 数量 单价 总价") for i in shopping_cart: print(i) print("您的余额为:",salary) print("------end------") break else: print("无此选项!")
标签:strip end ping src com product pen 序号 menu
原文地址:http://www.cnblogs.com/adamans/p/6836369.html