python_24_test
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的更多相关文章
随机推荐
- Gradle安装配置
1.构建工具的简单介绍在代码世界中有三大构建工具,ant.Maven和Gradle. 现在的状况是maven和gradle并存,gradle使用的越来越广泛. Maven使用基于XML的配置,Grad ...
- Exadata中的dbserver_backup.sh脚本
dbserver_backup.sh脚本在老版本的exadata中,它存放在/opt/oracle.SupportTools目录中,主要用于/根文件系统和/boot分区的备份.dbserver_bac ...
- PHP 获取acm近期比赛
<?php // author: Moore Jiang. ini_set('display_errors',1); //错误信息 ini_set('display_startup_errors ...
- js:数组里面获取键名和键值
在写php时用ajax异步传回的返回数组时是json格式,在js里面处理时有时需要用到键名,此时可以用in来处理 js只有数字索引: <script> var data = new arr ...
- spring boot与 spring.factories
spring boot启动加载过程 META-INF下面的spring.factories 解析@Configuration https://www.jianshu.com/p/346cac67bfc ...
- jquery——属性操作、特殊效果
1. attr().prop() 取出或者设置某个属性的值 <!DOCTYPE html> <html lang="en"> <head> &l ...
- 002 Add Two Numbers 链表上的两数相加
You are given two non-empty linked lists representing two non-negative integers. The digits are stor ...
- 禁用thinkpad触摸板的方法
控制面板----硬件和声音----设备和打印机----鼠标----ThinkPad------开启触摸板(前面的勾勾去掉)
- Java文件与io——缓冲流
对文件或其它目标频繁的读写操作,效率低,性能差. 使用缓冲流的好处,能够更高效的读写信息,原理是将数据先缓冲起来,然后一起写入或者读取出来. BufferedInputStream:为另一个输入流添加 ...
- agc015F - Kenus the Ancient Greek(结论题)
题意 题目链接 $Q$组询问,每次给出$[x, y]$,定义$f(x, y)$为计算$(x, y)$的最大公约数需要的步数,设$i \leqslant x, j \leqslant y$,求$max( ...