extr_shopping
__author__ = 'ZZG' # noinspection PyCallingNonCallable
shopping_list =[
("iphone",5300),
("book",55),
("watch",2200),
("bike",950),
("pc",11000),
("VR glass", 1000)
]
goods_list=[]#购买商品清单
salary = input("please enter you salary:")
#判断工资是否为数字
if salary.isdigit():
salary = int(salary)
#打印商品编号和商品
while True:
for index,item_list in enumerate(shopping_list):
print(index,item_list)
product_num = input("你想买什么物品,请输入编号:")
#判断商品编号是否为数字
if product_num.isdigit():
product_num = int(product_num)
#判断用户输入的商品编号是否在列表中
if product_num < len(shopping_list) and product_num >= 0:
#选择的商品
p_item = shopping_list[product_num]
#判断工资能否购买选择的商品
if salary > p_item[1]:
goods_list.append(p_item)
salary -= p_item[1]
print("---------已购买的商品列表---------")
print("你成功购买了%s,你的余额为\033[032;1m%s\033[0m"% (p_item,salary))
else:
print("你的余额为\033[031;1m%s\033[0m,就这点钱还想买东西!"%(salary))
else:
print("\033[031;1minvalid input\033[0m") elif product_num == "q":
print("---------已购买的商品列表--------")
for p in goods_list:
print(p)
print("你当前余额为:",salary)
exit() else:
print("\033[031;1minvalid input\033[0m") else:
print("\033[031;1minvalid input\033[0m")
这个代码和购物车实现的是一样,可是代码风格就不一样了,有了不一样的感觉!很好使
extr_shopping的更多相关文章
随机推荐
- 从Matlab文件中读取mxArray类型变量-部分代码分析
这是我做的笔记,看到这个代码时觉得处理有点妙,做笔记记录之. 部分源代码: .... int main(int argc,char** argv) { char name[_FILE_NAME_LEN ...
- hbase的HQuorumPeer和QuorumPeerMain
hbase是列式数据库,既可以单机也可以以集群的方式搭建,以集群的方式搭建一般建立在hdfs之上. 分布式的hbase如何启动? 首先启动hadoop,然后就来问题了:zookeeper和hbase的 ...
- 利用PowerShell 得到 进程总共占用的内存
$task = tasklist /nh /fo csv $total = 0 for($i=0; $i -lt $task.count; $i++) { $one = $task[ $i ].Spl ...
- pgjdbc源码分析
一. 源代码目录结构 pgjdbc的源码结构如下图: 那么我们来一一看看各个模块都是做什么的吧. 1 core 该目录是程序的核心模块目录. 这里实现了大部分pgjdbc的基类和接口,例如statem ...
- TF30042: The database is full. Contact your Team Foundation Server administrator.
TF30042: The database is full. Contact your Team Foundation Server administrator. 在一个阳光明媚的下午,迁入代码的时候 ...
- 通过游戏认识 --- JQuery与原生JS的差异
前言 jQuery是一个快速.简洁的JavaScript框架,是继Prototype之后又一个优秀的JavaScript代码库( 或JavaScript框架).jQuery设计的宗旨是“write ...
- How To Use Linux epoll with Python
http://scotdoyle.com/python-epoll-howto.html Line 1: The select module contains the epoll functional ...
- 手动安装Eclipse的PyDev插件,重启无效
想好好学习Python,又不想只用Emeditor开发,于是想到了Eclipse.之前配置过PyDev,很久没用,就放下了.这次重新配置,遇到了不少问题总结如下: 第一,使用网址自动更新.从网上搜了很 ...
- Winform界面中实现菜单列表的动态个性化配置管理
在我们一般的应用系统里面,由于系统是面向不同类型的用户,我们所看到的菜单会越来越多,多一点的甚至上百个,但是我们实际工作接触的菜单可能就是那么几个,那么对于这种庞大的菜单体系,寻找起来非常不便.因此对 ...
- linux top结果保存到文本上
[root@web-DB script]# cat top.sh # !/bin/bash today=`date +%Y%m%d%H%M` yesterday=`date -d "1 da ...