Python day3 知识总结
if salary.isdigit():
salary = int(salary)
判断输入的salary是否是一个整数是否成立
for index,item in enumerate(product_list):
#print(product_list.index(item),item)
print(index,item)
index就是下标,enumerate()的作用是取出列表的下标,item是数据; 老师写的购物车:
product_list = [
('Iphone',5800),
('Mac Pro',9800),
('Bike',800),
('Watch',10600),
('Coffee',31),
('Alex Python',120),
]
shopping_list = []
salary = input("Input your salary:")
if salary.isdigit():
salary = int(salary)
while True:
for index,item in enumerate(product_list):
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) )
else:
print("\033[41;1m你的余额只剩[%s]啦\033[0m" % salary)
else:
print("product code [%s] is not exist!"% user_choice)
elif user_choice == 'q':
print("--------shopping list------")
for p in shopping_list:
print(p)
print("Your current balance:",salary)
exit()
else:
print("invalid option")
Python day3 知识总结的更多相关文章
- Python day3 知识回顾
names = ["Jonathen","Joesph","Jotaro","Josuke",["Mea&qu ...
- 【Python五篇慢慢弹(5)】类的继承案例解析,python相关知识延伸
类的继承案例解析,python相关知识延伸 作者:白宁超 2016年10月10日22:36:57 摘要:继<快速上手学python>一文之后,笔者又将python官方文档认真学习下.官方给 ...
- Python开发【第二篇】:Python基础知识
Python基础知识 一.初识基本数据类型 类型: int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2147483648-2147483647 在64位 ...
- python基础知识(二)
以下内容,作为python基础知识的补充,主要涉及基础数据类型的创建及特性,以及新数据类型Bytes类型的引入介绍
- python 基础知识(一)
python 基础知识(一) 一.python发展介绍 Python的创始人为Guido van Rossum.1989年圣诞节期间,在阿姆斯特丹,Guido为了打发圣诞节的无趣,决心开发一个新的脚本 ...
- 适用于 PHP 开发人员的 Python 基础知识
Thomas Myer, 负责人, Triple Dog Dare Media 简介: 您是一名经验丰富的 PHP 开发人员,并且希望学习 Python 吗?本文将从 PHP 开发人员的角度来探索 P ...
- python基础知识讲解——@classmethod和@staticmethod的作用
python基础知识讲解——@classmethod和@staticmethod的作用 在类的成员函数中,可以添加@classmethod和@staticmethod修饰符,这两者有一定的差异,简单来 ...
- python爬虫主要就是五个模块:爬虫启动入口模块,URL管理器存放已经爬虫的URL和待爬虫URL列表,html下载器,html解析器,html输出器 同时可以掌握到urllib2的使用、bs4(BeautifulSoup)页面解析器、re正则表达式、urlparse、python基础知识回顾(set集合操作)等相关内容。
本次python爬虫百步百科,里面详细分析了爬虫的步骤,对每一步代码都有详细的注释说明,可通过本案例掌握python爬虫的特点: 1.爬虫调度入口(crawler_main.py) # coding: ...
- Python数据分析-知识宝藏
0.SQL数据库 1. python基础知识 2. 重点工具掌握:数据解析核心技巧 - Numpy| Pandas| Matplotlib 3. 数据特征分析:分布| 对比| 统计| 帕累托| 正态| ...
随机推荐
- [JSOI2018]潜入行动 树形DP_复杂计数
code #include <cstdio> #include <algorithm> #include <cstring> #include <string ...
- bzoj 2259: [Oibh]新型计算机 最短路 建模
Code: #include<cstdio> #include<cstring> #include<algorithm> #include<queue> ...
- 新机器的vim配置
最近一直用vim去写acm代码,算是一种练习吧. 用着用着感觉不错,最近也稍微配置了一下vim,用着更舒服了 键盘映射 ESC<->CapsLock 我们知道vim有自带的键盘映射命令,但 ...
- HDU-1789 Doing Homework again 贪心问题 有时间限制的最小化惩罚问题
题目链接:https://cn.vjudge.net/problem/HDU-1789 题意 小明有一大堆作业没写,且做一个作业就要花一天时间 给出所有作业的时间限制,和不写作业后要扣的分数 问如何安 ...
- Unity 模拟点击Home键和启动其他app
using System.Collections; using System.Collections.Generic; using UnityEngine; public class NewBehav ...
- 【Round #36 (Div. 2 only) C】Socks Pairs
[题目链接]:https://csacademy.com/contest/round-36/task/socks-pairs/ [题意] 给你n种颜色的袜子,每种颜色颜色的袜子有ai只; 假设你在取袜 ...
- HDFS 断点续传,写文件功能
实际上这是个 HDFS 的工具类部分代码. 首先 public static Configuration configuration = null;public static FileSystem f ...
- Ubuntu下安装git工具
环境:Ubuntu 9.10 git-1.8.2.3.tar.bz2 1.将安装包下载到所选文件夹下,如:/tmp 2.tar -xjf git-1.8.2.3.tar.bz2 3.cd git-1. ...
- 设计模式 - 组合模式(composite pattern) 迭代器(iterator) 具体解释
组合模式(composite pattern) 迭代器(iterator) 具体解释 本文地址: http://blog.csdn.net/caroline_wendy 參考组合模式(composit ...
- 积跬步,聚小流------Bootstrap学习记录(2)
现阶段开启每一次新的征程,已然离不开"Hello World"的习惯仪式.这次自然也不例外.先来看下给出的官网给出的演示样例: 1.bootstrap官网提供的html基本模板代码 ...