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的更多相关文章
随机推荐
- bzoj3720: Gty的妹子树(树分块)
传送门 好珂怕…… 树分块是什么东西啊……感觉好暴力…… 直接贴一下好了->这里 //minamoto #include<iostream> #include<cstdio&g ...
- github上虽然已经有实现好的Char RNN
前言 学习RNN的时候很多人应该都有看过Andrej Karpathy写的The Unreasonable Effectiveness of Recurrent Neural Networks,使用基 ...
- POJ2388-Who's in the Middle
题目链接:点击打开链接 Who's in the Middle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45683 ...
- chromedriver对应chrom版本
chromedriver版本 支持的Chrome版本 v2.37 v64-66 v2.36 v63-65 v2.35 v62-64 v2.34 v61-63 v2.33 v60-62 v2.32 v5 ...
- Jmeter ExcelDataPreProcessor
Jmeter的预处理器主要是用来在采样器(sample)被执行之前做一些额外的工作,比如参数化等等. 本文写一个例子来说明如何增加一个预处理器,需求如下:我们想在执行采样器前读取Excel文件中的数据 ...
- 利用Python的smtplib和email发送邮件
原理 网上已经有了很多的教程讲解相关的发送邮件的原理,在这里还是推荐一下廖雪峰老师的Python教程,讲解通俗易懂.简要来说,SMTP是发送邮件的协议,Python内置对SMTP的支持,可以发送纯文本 ...
- PHPExcel探索之旅---阶段三 绘制图表
利用PHPExcel插件进行绘制图表 <?php /** * 使用PHPExcel插件在excel文件中利用其中的数据建立折线图 * */ $dir = dirname(__FILE__); r ...
- LeetCode 236 Lowest Common Ancestor of a Binary Tree 二叉树两个子节点的最低公共父节点
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...
- (转)linux磁盘分区fdisk分区和parted分区
linux磁盘分区fdisk分区和parted分区 原文:http://www.cnblogs.com/jiu0821/p/5503660.html ~~~~~~~~~~~~~~~~~~~~~~~~~ ...
- (转)不看绝对后悔的Linux三剑客之awk实战精讲
原文:http://blog.51cto.com/hujiangtao/1923930 一.Linux三剑客之awk命令精讲 第1章 awk基础入门 1.1 awk简介 awk不仅仅时linux系统中 ...