product_list = [('iPhone',5800),('Mac Pro',9500),('Bike',800), ('Apple Watch',10600),("Coffee",31),("Alex Python",120)] shopplist_list = [] salary = input("Input your salary:") if salary.isdigit(): salary = int(salary) while True: 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 < len(product_list) and user_choice >=0: p_item = product_list[user_choice] if p_item[1] <= salary: shopplist_list.append(p_item) salary = salary - p_item[1] print("added %s into shopping cart,you current balance is %s"%(p_item,salary)) else: print("你的余额只剩[%s]啦,余额不足" % salary) else: print("product code [%s] is not exist!" % user_choice) elif user_choice == 'q': print("------shooping list------") for p in shopplist_list: print(p) print("your current balance:",salary) exit() else: print("invalid option")
购物车程序
原创
©著作权归作者所有:来自51CTO博客作者leiwenbin627的原创作品,请联系作者获取转载授权,否则将追究法律责任

提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
购物车的实现(未登录时也可以使用)
平时工作的踩坑记录
redis List 拦截器 -
python之购物车程序
题目:购物车程序业需求
python 小练 -
Python开发购物车程序
用Python开发一个购物车程序案例
脚本 Python 购物车 -
Python简单的购物车程序
刚开始学习Python做的购物车练习
Python 购物车