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. 源代码实现一个binary例子

    一.源代码实现一个binary例子 1.例子描述 (1) 数据描述 输入数据X是二进制的一串序列, 在t时刻,有50%的概率是1,50%的概率是0,比如:X=[1,1,0,0,1,0.....]输出数 ...

  2. POJ1027 The Same Game

    题目来源:http://poj.org/problem?id=1027 题目大意: 题目说的就是现在蛮流行的手机小游戏popstar,求用贪心方法能得到多少分. 小球有三种颜色:R/G/B.横向.纵向 ...

  3. element-ui国际化探索(大型项目适用)

    配置好了,自己感觉是比较简单的,就是有一点点繁琐,加油吧. 由于保密,无法拿出项目,故写了一个小demo,记录一下,适用于大型项目: 项目中需要自定义切换中/英文(国际化),基于vue.js,结合vu ...

  4. HTTP的学习记录(二)头部

    本文主要讲一些 HTTP头部的信息 首先看一段 惊为天人 的文章. 来自于 <淘宝技术这十年> 你发现快要过年了,于是想给你的女朋友买一件毛衣,你打开了www.taobao.com.这时你 ...

  5. Unraveling the JPEG file

    (文章还剩实践部分没写,答辩过后补上...) JPEG文件在当下数字化生活中是无处不在的,但是在熟悉的JPEG面纱背后,隐藏着一些算法,它们去除了人类眼中无法察觉到的细节.这产生了最高的视觉质量与最小 ...

  6. wms-springmvc-servlet.xml

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  7. myeclipse-9.0安装svn客户端插件

    SVN插件配置到MyEclipse中的步骤 听语音 | 浏览:20471 | 更新:2015-01-09 10:26 | 标签:myeclipse 1 2 3 4 5 6 7 分步阅读 MyEclip ...

  8. Jmeter4.0----正则表达式提取器(12)

    1.说明 有时候需要将前一个请求返回的数据作为下一个请求的参数时,我们就需要正则表达式提取器.使用正则表达式提取器去提取我们想要的部分再传入后面的请求中. (之前看了一篇不错的博客,可以参考学习 ht ...

  9. Win10创建还原点

    Win + E打开任务管理器 右击此电脑,选择属性 单击高级系统设置 选择系统保护 单击系统还原 按照提示操作,OK.

  10. (转)rename命令详解

    rename命令详解: 原文:http://www.cnblogs.com/amosli/p/3491649.html 对文件重命名是常用的操作之一,一般对单个文件的重命名用mv命令,如: amosl ...