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. 洛谷P1360 [USACO07MAR]黄金阵容均衡Gold Balanced L…

    P1360 [USACO07MAR]黄金阵容均衡Gold Balanced L… 题目描述 Farmer John's N cows (1 ≤ N ≤ 100,000) share many simi ...

  2. [Xcode 实际操作]四、常用控件-(1)UIButton控件的使用

    目录:[Swift]Xcode实际操作 本文将演示按钮控件的使用,按钮是用户界面中最常见的交互控件 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import U ...

  3. 避免picture图片无法删除,提示正在被其他进程使用

    pictureBox1.Image = Image.FromStream(ByteToStream(SetImageToByteArray(cutImgPath))); #region 将文件转换成流 ...

  4. Angular学习笔记【ngx-bootstrap】中的 tabset

    <tabset class="tab-container tabbable-line"> <tab heading="{{l("MobileS ...

  5. Flask&&人工智能AI --1

    Flask初识,Response三剑客,jsonify以及send_file.Request,模板语言 Jinja2,用户登录例子,内置Sessio 一.Flask初识 首先,要看你学没学过Djang ...

  6. jQuery Plugin Poshy Tip 使用 统一提示信息

    项目到了后期,发现前端的提示信息不统一,解决思路如下: 1.回顾系统中tip出现的场景:表单验证提示信息.数据列表中随填随显 2.确定问题域:多条提示信息层叠.信息显示风格不统一 3.结论:找出一款合 ...

  7. IDEA 工具使用指南

    给项目增加jdk , 方便查看不同版本的jdk源码 鼠标滚轮放大缩小字体 wheel zoom 设置JVM参数 https://www.jetbrains.com/help/idea/tuning-t ...

  8. 011 Container With Most Water 盛最多水的容器

    给定 n 个非负整数 a1,a2,…,an,每个数代表坐标中的一个点 (i, ai) .画 n 条垂直线,使得垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线,使得它们 ...

  9. nginx去掉url中的index.php

    使用情境:我想输入www.abc.com/a/1后,实际上是跳转到www.abc.com/index.php/a/1 配置Nginx.conf在你的虚拟主机下添加: location / {      ...

  10. vulhub-php/php_inclusion_getshell

    注:本地测试php文件包含+phpinfo泄露导致getshell,此漏洞与php版本无关 使用vulhub环境进行复现: 项目地址:https://github.com/vulhub/vulhub/ ...