product_list=[
('Iphone',5800),
('Mac Pro',9800),
('Bike',800),
('Watch',10600),
('Coffee',31),
('Python Book',49)
]
shopping_list=[]
salary=input('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):#enumerate 取出列表的下表
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:#买得起
shopping_list.append(p_item)
salary-=p_item[1]
print("Added %s into shopping cart,your current balance is \033[31;1m%s\033[0m"%(p_item,salary))#\033[31;1m%s\033[0m表示红色
else:
print('\033[41;1m你的余额只剩[%s]啦,还买个毛线\033[0m'%salary)#41是背景红,32是绿色,42是背景绿
else:
print("商品[%s]不存在"%user_choice)
elif user_choice=='q':
print('--------shopping list---------')
for p in shopping_list:
print(p)
print("你的余额:" ,salary)#print("你的余额:%s"%salary)
exit()
else:
print('invalide option')

  

python_24_test的更多相关文章

随机推荐

  1. 60个DevOps开源工具,你在用哪些?

    你喜欢免费的东西吗?获得开发者社区支持的自动化,开源的工具是大家梦寐以求的.这里列举了 60 多款最棒的开源工具,可以帮助你很好的实行 DevOps. 一.开发工具 版本控制&协作开发 1.版 ...

  2. 基础篇:MySQL系列之三

    一.MySQL简介 ​ MySQL原本是一个开放源代码的关系数据库管理系统,原开发者为瑞典的MySQL AB公司,该公司于2008年被Sun公司收购.2009年,Oracle收购sun公司,MySQL ...

  3. 记录一下我的三天清明节假期,TP5.1写企业站

    在假期前就计划利用这三天时间写一个企业站,包括pc和wap,和微信公众平台 在计划时有些功能没有想好,导致后面踩了不少坑,前期计划一定要尽量做详细,表字段设计也要考虑好,不然后期开始写代码时会需要来回 ...

  4. Eclipse设置控制台字体

    打开 Window - preferences-- general - appearance - colors and fonts --debug - console font 进行设置.

  5. CF24D Broken robot 后效性DP

    这题咕了好久..... 设$f[i][j]$表示从$(i,j)$到最后一行的期望步数: 则有 $ f[i][1]=\frac{1}{3}(f[i][1]+f[i][2]+f[i+1][1])+1$ $ ...

  6. Docker从入门到实战(三)

    Docker从入门到实战(三) 一:安装Docker 1. linux系统脚本安装 Docker基于linux容器技术,面向服务器端,Docker只能安装运行在64位计算机上(社区有对32位的支持), ...

  7. Zookeeper问题汇总

    1. 遗留问题 a). zookeeper集群如何保证请求的均匀分布? 2. ZK概念澄清 2.1 ZK节点类型 CreateMode.PERSISTENT //持久节点,该节点客户端断开后不会删除 ...

  8. WCF 内置绑定在不同的传输安全模式下的信道层

    basicHttpBinding Transport安全模式信道层 Message安全模式信道层 TransportWithMessageCredential安全模式信道层 TransportCred ...

  9. [Java][Liferay] 解决Liferay ext项目deploy的问题

    Liferay ext project在install war包之后需要重启服务器,重启服务器中会执行ExtHotDeployListener中的逻辑,这里有一个坑,如果是第二次以后install e ...

  10. GitLab-CE-8.9.4 (OpenLogic CentOS 7.2)

    平台: CentOS 类型: 虚拟机镜像 软件包: gitlab-8.9.4 bug tracking collaboration commercial development devops git ...