标签:git one enum 无效 购物车 coff use list money
shangpin_list = [ (‘Iphone‘,4000), (‘Mac por‘,9000), (‘python book‘,40), (‘car‘,14000), (‘photoshop book‘,60), (‘food‘,50), (‘coffee‘,30), ] while True: money = input(‘请输入你的钱数,或者按q结束:\n‘) if money.isdigit(): break else: print(‘请继续输入正确的钱数‘) shopping_list = [] if money.isdigit(): money = int(money) while True: for index,item in enumerate(shangpin_list): print(index,item) user_select = input(‘选择你需要的商品编号,或者按q结束:\n‘) if user_select.isdigit(): user_select = int(user_select) if user_select < len(shangpin_list) and user_select >=0: p_item = shangpin_list[user_select] if p_item[1] <= money: shopping_list.append(p_item) money -= p_item[1] print("将%s添加到购物车中,您当前的余额为\033[31;1m%s\033[0m "%(p_item,money)) else: print("\033[41;1m你的余额只剩[%s]啦,还买个毛啊\033[0m"%money) else: print(‘无效的选择,商品不存在‘) elif user_select == ‘q‘: print("-----------------已购商品列表-----------------") for p in shopping_list: print(p) print(‘你的余额:‘,money) exit()
标签:git one enum 无效 购物车 coff use list money
原文地址:http://www.cnblogs.com/hahahahaha/p/6910888.html