product_list=[ ("Iphone",5800), ("Mac Pro",9800), ("Bike",800), ("Watch",10600), ("Coffee",32), ("Alex Python",80) ] shopping_list=[] salary=input("请输入你的工资:") if salary.isdigit(): salary=int(salary) while True: for index,item in enumerate(product_list): print(index,item) user_code=input("请输入你要选择的商品编码:") if user_code.isdigit(): user_code=int(user_code) if user_code<len(product_list) and user_code>=0: p_item=product_list[user_code] if salary>=p_item[1]: shopping_list.append(p_item) salary-=p_item[1] print("该商品已加入购物车:\033[31;1m%s\033[0m,你的工资余额为:\033[31;1m%s\033[0m"%(p_item,salary)) else: print("你的工资不足以购买:\033[32;1m%s\033[0m,你的工资为:\033[32;1m%s\033[0m"%(p_item,salary)) else: print("商品编码%s不存在"%user_code) elif user_code=="q": print("-------商品列表-------") for p in shopping_list: print(p) print("剩余工资余额为:",salary) exit() else: print("输入无效")
简易购物车系统,无界面
最新推荐文章于 2019-01-06 19:23:16 发布