python购物车程序简单代码
更新时间:2018年04月18日 10:21:46 作者:不会代码的程序员
这篇文章主要为大家详细介绍了python购物车程序的简单代码,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了python购物车程序的具体代码,供大家参考,具体内容如下
代码:
'''''
Created on 2017年9月4日
@author: len
'''
product_list = [
('Robot',200000),
('MacPro',12000),
('Iphone8',8888),
('Hello World',1200),
]
shopping_list = []
user_salary=input("请输入你的工资:")
if user_salary.isdigit():
user_salary = int(user_salary)
while True:
print("商品如下:")
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 > -1:
p_item = product_list[user_choice]
if user_salary>=p_item[1]:
shopping_list.append(p_item)
user_salary-=p_item[1]
print("购买商品",p_item,"成功您的余额为",user_salary,"元!" )
else:
print("您的余额为",user_salary,"余额不足以购买此商品,购买失败!")
else:
print("并无此产品!")
elif user_choice == "q":
print("--------shopping list-------")
for i in shopping_list:
print(i)
exit()
else:
print("invalidate!!!")
效果图:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
使用python本地部署DeepSeek运行时报错 OSError: [WinError 193] %1 不是
文章介绍了在本地使用Python部署DeepSeek时遇到的OSError: [WinError 193] 错误,通过检查错误信息,发现与numpy版本有关,解决方法是卸载并重新安装numpy,最终,问题得到解决,感兴趣的朋友跟随小编一起看看吧2025-02-02
解决Pycharm 中遇到Unresolved reference ''sklearn''的问题
这篇文章主要介绍了解决Pycharm 中遇到Unresolved reference 'sklearn'的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2020-07-07


最新评论