Python 简单购物程序
# Author:Eric Zhao
# -*- coding:utf-8 -*-
'''需求:
启动程序后,让用户输入工资,然后打印商品列表
允许用户根据商品编号购买商品
用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒
可随时退出,退出时,打印已购买商品和余额''' product_list = [
('IPhone',5000),
('Bike', 500),
('Car', 50000),
('Hat', 50)
]
shopping_list = []
salary = input('Please input your salary..')
if salary.isdigit():
salary = int(salary)
while True: # 死循环
# for item in product_list:
# print(product_list.index(item),item)
for index,item in enumerate(product_list):
print(index,item) user_choice = input('Please type a product number,if type q then exit..')
if user_choice.isdigit():
user_choice = int(user_choice)
if user_choice < len(product_list) and user_choice>=0:
choice_list = product_list[user_choice]
if salary >= choice_list[1]: # 买得起
shopping_list.append(choice_list)
salary = salary - choice_list[1]
print('Added %s into shopping cart,your balance is\033[31;1m%d\033[0m'%(choice_list,salary))
else:
print('Your balance is only \033[31;1m%d\033[0m,not enough..'%salary)
else:
print('The product number [\033[31;1m%d\033[0m] doesn\'t exist..'%user_choice)
elif user_choice == 'q':
print('------------------- shopping list --------------------')
for mylist in shopping_list:
print(mylist)
print('Your balance is \033[31;1m%d\033[0m'%salary)
exit()
else:
print('Invalid number')
else:
print('Please type a integer..')
Python 简单购物程序的更多相关文章
- python ATM购物程序
需求: 模拟实现一个ATM + 购物商城程序 额度 15000或自定义 实现购物商城,买东西加入 购物车,调用信用卡接口结账 可以提现,手续费5% 每月22号出账单,每月10号为还款日,过期未还,按欠 ...
- Python简单小程序练习
1.九九乘法表 #!/usr/bin/python for i in range(1,10): for j in range(i): j += 1 print ("%d * %d = %-2 ...
- python简单小程序
#足球队寻找10 到12岁的小女孩(包含10岁和12岁),编写程序询问用户性别和年龄,然后显示一条消息指出这个人是否可以加入球队,询问10次,输出满足条件的总人数#询问10次,输出满足要求的总人数 o ...
- 用python开发简单ftp程序
根据alex老师视频开发的简单ftp程序,只能实现简单的get功能 ftp客户端程序: #!/usr/bin/env python #_*_ coding:utf-8 _*_ import socke ...
- python简单的监控脚本-利用socket、psutil阻止远程主机运行特定程序
python简单的监控脚本-利用socket.psutil阻止远程主机运行特定程序 psutil是一个跨平台的库(http://code.google.com/p/psutil/),能够轻松的实现获取 ...
- 简单购物车程序(Python)
#简单购物车程序:money_all=0tag=Trueshop_car=[]shop_info={'apple':10,'tesla':100000,'mac':3000,'lenovo':3000 ...
- [terry笔记]python购物程序
如下是一个购物程序: 先输入工资,显示商品列表,购买,quit退出,最后格式化输出所买的商品. count = 0 while True: #做一个循环判断,如果输入的不是数字,基于提示,三次后退出 ...
- Python简单爬虫入门二
接着上一次爬虫我们继续研究BeautifulSoup Python简单爬虫入门一 上一次我们爬虫我们已经成功的爬下了网页的源代码,那么这一次我们将继续来写怎么抓去具体想要的元素 首先回顾以下我们Bea ...
- GJM : Python简单爬虫入门(二) [转载]
感谢您的阅读.喜欢的.有用的就请大哥大嫂们高抬贵手"推荐一下"吧!你的精神支持是博主强大的写作动力以及转载收藏动力.欢迎转载! 版权声明:本文原创发表于 [请点击连接前往] ,未经 ...
随机推荐
- 【bzoj4567】[Scoi2016]背单词
4567: [Scoi2016]背单词 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1123 Solved: 476[Submit][Status][ ...
- echart 初级尝试
var option = { title: { text: 'ECharts 入门示例'//标题 }, legend: { data:['销量']//图例 }, xAxis: { data: [&qu ...
- element-ui关于form表单在dialog中的重置
form表单的重置是以第一次打开的数据作为重置标准,如果先打开的是更新,那么重置之后以第一次更新的数据作为标准; Dialog 中的内容是懒加载的,目前 edit (更新)方法的写法导致 Form 刚 ...
- Ubuntu新服务器安装lnmp
版本: nginx(无要求,最新) mysql(5.6.xx) php(5.6.xx) ubuntu(16.04,其他版本也并无过多差异) 准备: #apt-get update #apt-get i ...
- shell 发送Post请求,并获取状态码
#!/bin/bash aa=$ result=$(curl -H "Content-type: application/json" -X POST -o /dev/null -s ...
- cocos2dx贝塞尔曲线--使用PS辅助规划动作路径
bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ...
- 模态框的理解 ,jQ: loading,进度条, 省级联动 表单验证 插件
模态框: 打开一个弹框 不关闭它就不能做框外的操作 必须关闭或弹出另外的弹框 加载延迟loading + 进度条只要有请求 就处理一下监控ajax 全局事件jquery: $('#box').ajax ...
- 《超实用的Node.js代码段》连载二:正确拼接Buffer
对于初学Node.js框架的开发人员来说,可能认为Buffer模块比较易学.重要性也不是那么突出.其实,Buffer模块在文件I/O和网络I/O中应用非常广泛,其处理二进制的性能比普通字符串性能要高出 ...
- wordpress安装后首页无法进入 The file 'wp-config.php' already exists
问题是缓存导致,具体还没研究是怎么产生的缓存.chrome浏览器解决方法: 1. 网址后面加参数进入网站 2. 打开控制台-network 3. 刷新页面 4. 控制台-network,右键请求的文件 ...
- mac不限速下载百度网盘
本文转载自:https://blog.csdn.net/u010837612/article/details/80029212 相信大家都比较困惑,百度网盘客户端限速后一般只有几十K的下载速度,Win ...