python购物车程序简单代码
作者:不会代码的程序员 时间:2021-02-15 23:11:46
本文实例为大家分享了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!!!")
效果图:
来源:https://blog.csdn.net/weixin_38626799/article/details/77836527
标签:python,购物车
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
几行Python代码爬取3000+上市公司的信息
2022-11-17 22:04:09
![](https://img.aspxhome.com/file/2023/3/107973_0s.png)
PyTorch 1.0 正式版已经发布了
2021-12-09 23:54:57
Windows下python3安装tkinter的问题及解决方法
2023-03-30 11:45:31
用户如何有效地利用ORACLE数据字典
2008-03-04 18:19:00
python网络爬虫精解之正则表达式的使用说明
2023-02-26 17:13:21
![](https://img.aspxhome.com/file/2023/7/104997_0s.png)
PHP源码之 ext/mysql扩展部分
2023-07-21 18:24:20
Python语法学习之进程的创建与常用方法详解
2023-11-08 11:23:34
![](https://img.aspxhome.com/file/2023/9/78609_0s.jpg)
python二叉树遍历的实现方法
2021-09-19 03:53:14
python实现图片素描效果
2022-06-10 21:00:40
![](https://img.aspxhome.com/file/2023/1/91841_0s.png)
Python实现小黑屋游戏的完整实例
2021-03-08 13:27:43
![](https://img.aspxhome.com/file/2023/5/67745_0s.png)
Python网络爬虫项目:内容提取器的定义
2021-05-29 21:51:43
![](https://img.aspxhome.com/file/2023/6/121036_0s.png)
Python3实现对列表按元组指定列进行排序的方法分析
2022-10-05 18:01:13
Python办公自动化从Excel中计算整理数据并写入Word
2021-12-19 03:22:35
![](https://img.aspxhome.com/file/2023/9/97409_0s.png)
浅谈Python用QQ邮箱发送邮件时授权码的问题
2021-10-30 13:06:59
![](https://img.aspxhome.com/file/2023/2/90942_0s.jpg)
网页标准化-CSS命名规划整理
2007-12-10 18:13:00
Redis IP地址的绑定的实现
2023-07-20 12:00:21
![](https://img.aspxhome.com/file/2023/0/59360_0s.png)
Oracle数据库的安全策略
2010-07-31 13:13:00
Python闭包之返回函数的函数用法示例
2022-12-09 18:50:41
![](https://img.aspxhome.com/file/2023/5/101195_0s.png)
人脸识别实战之Opencv+SVM实现人脸识别
2021-01-06 09:32:13
![](https://img.aspxhome.com/file/2023/5/72775_0s.png)
python浪漫表白源码
2023-11-22 05:16:39
![](https://img.aspxhome.com/file/2023/0/67830_0s.jpg)