014--python运算符和作业改进
一、运算符
% 取模,返回商的余数
10/3 3.33333333335
10//3 3 地板除,取整数,不是四舍五入
a = 3 b = 5 -----> a<b and a==4 or b<10 and a>1
or前面的条件成立,则不走or后面的式子;or前面的条件不成立,则不考虑前面的式子,直接运算后面的
'123'.isdigit() 判断一个字符串是否可以转换为数字
身份判断:type(123) is int type('123') is str
位运算:
128 64 32 16 8 4 2 1
a=60 0 0 1 1 1 1 0 0
b=13 0 0 0 0 1 1 0 1
&按位与 0 0 0 0 1 1 0 0
|按位或 0 0 1 1 1 1 0 1
二、作业
三级菜单(low版)
menu = {
'北京':{
'海淀':{
'五道口':{
'soho':{},
'网易':{},
'google':{}
},
'中关村':{
'爱奇艺':{},
'汽车之家':{},
'youku':{},
},
'上地':{
'百度':{},
},
},
'昌平':{
'沙河':{
'老男孩':{},
'北航':{},
},
'天通苑':{},
'回龙观':{},
},
'朝阳':{},
'东城':{},
},
'上海':{
'闵行':{
"人民广场":{
'炸鸡店':{}
}
},
'闸北':{
'火车战':{
'携程':{}
}
},
'浦东':{},
},
'山东':{},
}
break_flag = True
while break_flag:
for i in menu:
print(i)
choice1 = input('>:').strip()
if len(choice1)==0:continue
if choice1=='q':
break_flag = False
continue
if choice1 in menu:
while break_flag:
for j in menu[choice1]:
print(j)
choice2 = input('>>:').strip()
if len(choice2)==0:continue
if choice2=='b':break
if choice2=='q':
break_flag = False
continue
if choice2 in menu[choice1]:
while break_flag:
for k in menu[choice1][choice2]:
print(k)
choice3 = input('>>>:').strip()
if len(choice3)==0:continue
if choice3=='b':break
if choice3=='q':
break_flag = False
continue
if choice3 in menu[choice1][choice2]:
while break_flag:
for m in menu[choice1][choice2][choice3]:
print(m)
choice4 = input('>>>>:')
if len(choice4)==0:continue
if choice4=='b':break
if choice4=='q':
break_flag = False
continue
购物车优化作业
shopping_cart = {} #购物车
product_list = [
['iphone',5800],
['小米手机',2000],
['茅台酒',650],
['笔',5],
['电饭锅',200]
]
salary = int(input('Input your salary:'))
while True:
index = 0
for product in product_list:
print(index,product)
index+=1
choice = input('请输入商品编号:')
if choice.isdigit():
choice = int(choice)
if choice>=0 and choice<=len(product_list):
product = product_list[choice]
if product[1] <= salary:
if product[0] in shopping_cart:
shopping_cart[product[1]]+=1
else:
shopping_cart[product[0]]=[product[1],1]
salary-=product[1]
print('购物车已添加:'+product[0]+' ,您的余额为:'+str(salary))
else:
print("工资不够,商品的价格为:%s ,还差:%s"%(str(product[1]),product[1]-salary))
else:
print('编号不存在,请重新输入')
elif choice=='q':
print('-----------您已购买以下商品-----------')
id_count = 1
total_cost = 0
print('id 商品 单价 数量 总价')
for key in shopping_cart:
print("%s\t\t%s\t\t%s\t\t%s\t\t%s"
%(id_count,
key,
shopping_cart[key][0],
shopping_cart[key][1],
shopping_cart[key][0]*shopping_cart[key][1]
)
)
id_count+=1
total_cost+=shopping_cart[key][0]*shopping_cart[key][1]
print('您的总花费为:%s'%total_cost)
print('您的余额为:%s'%salary)
print('----------------end---------------')
else:
print('编号输入错误')
014--python运算符和作业改进的更多相关文章
- python运算符重载
python运算符重载就是在解释器使用对象内置操作前,拦截该操作,使用自己写的重载方法. 重载方法:__init__为构造函数,__sub__为减法表达式 class Number: def __in ...
- Python运算符,python入门到精通[五]
运算符用于执行程序代码运算,会针对一个以上操作数项目来进行运算.例如:2+3,其操作数是2和3,而运算符则是“+”.在计算器语言中运算符大致可以分为5种类型:算术运算符.连接运算符.关系运算符.赋值运 ...
- Python运算符与表达式
Python运算符包括赋值运算符.算术运算符.关系运算符.逻辑运算符.位运算符.成员运算符和身份运算符. 表达式是将不同类型的数据(常亮.变量.函数)用运算符按照一定得规则连接起来的式子. 算术运算符 ...
- (三)Python运算符
一.python运算符相关 Python语言支持以下类型的运算符: 算术运算符 比较(关系)运算符 赋值运算符 逻辑运算符 位运算符 成员运算符 身份运算符 运算符优先级 1.python算数运算符 ...
- 【Python 补充01】Python运算符
Python运算符 举个简单的例子 4 +5 = 9 . 例子中,4 和 5 被称为操作数,"+" 称为运算符. 1.算术运算符 + - * / # 加减乘除 % # 取模(返回除 ...
- python运算符与数据类型
python运算符 Python语言支持以下类型的运算符: 算术运算符 比较(关系)运算符 赋值运算符 逻辑运算符 位运算符 成员运算符 身份运算符 运算符优先级 以下假设变量: a=10,b=20: ...
- Python——运算符
Python算术运算符 以下假设变量: a=10,b=20: 运算符 描述 实例 + 加 - 两个对象相加 a + b 输出结果 30 - 减 - 得到负数或是一个数减去另一个数 a - b 输出结果 ...
- Python学习day5作业
目录 Python学习day5作业 ATM和购物商城 1. 程序说明 2. 基本流程图 3. 程序测试帐号 4. 程序结构: 5. 程序测试 title: Python学习day5作业 tags: p ...
- 基于python复制蓝鲸作业平台
前言 去年看武sir代码发布的视频无意中听到了蓝鲸平台但是一直没深究,前一段时间公司要搞一个代码发布平台,但是需求变化很多一直找不到一个很好的参考 模板,直到试用了一下蓝鲸作业平台发现“一切皆作业”的 ...
随机推荐
- 关于android分享(sharedsdk的简单使用)
老早就使用了.可是如今才写,惰性太大,如今改 如今做产品的话相信大家基本都做分享吧.一个是项目的需求须要,另一个是能够非常好的宣传自己的产品.其它的优点依据情况而论 事实上每一个平台都有它自己的文档, ...
- uml精粹——10.状态机图
10.状态机图state machine diagram 状态机图是常见的描写叙述一个系统行为的技术. 在面向对象的方法中,为单个类绘制一个状态机图来展示单个对象的生命周期行为. 见图10.1 图 ...
- 生活娱乐 VERYCD的T恤设计大赛
http://www.verycd.com/event/tee2011/ 购买网站: http://dianlv.taobao.com/
- Koala - 使用
几天项目又加紧,样式想写又太慢! 下载考拉:http://pc6.dun.123ch.cn/download/koala%E7%BC%96%E8%AF%91%E5%B7%A5%E5%85%B7_30@ ...
- VBA 把电信的电话费用表转换成部门电话费用明细表(图文)
今天同事要做一个这种工作.就是把电信发来的费用表,转换成按部门划分的电话费用表,100多部电话,假设一个个去核对,真还是须要些时间的.问题来了,有更好的方法么,我们来看一下. 电信公司给的费用明细是这 ...
- sed 修连接文件,有坑
-bash-4.1# ll /etc/rc.local lrwxrwxrwx. 1 root root 13 Aug 15 2014 /etc/rc.local -> rc.d/rc.loc ...
- Android逆向利器和smali代码修改出错举例-入参类型
当smali修改代码出错举例1,log如下: 虚拟机层次: 1.本身做出了预测,寄存器v2是符合要求入参,暗示你这个也许是你想要的.VFY: register1 v2 type 17, wanted ...
- PandoraBox 支持3G无线上网卡(联通卡3G卡)(一)
一:笔者采用的是系统是OpenWrt之PandoraBox,内核版本3.3.8:硬件设备是MTK的7620开发板. 其中怎么搭建openwrt开发环境在此不用多说,因为既然想实现3G无线上网卡拨号上网 ...
- HDU 6183 Color it cdq分治 + 线段树 + 状态压缩
Color it Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Pro ...
- jQuery.ajaxSetup()
jQuery.ajaxSetup()函数用于设置AJAX的全局默认设置. 该函数用于更改jQuery中AJAX请求的默认设置选项.之后执行的所有AJAX请求,如果对应的选项参数没有设置,将使用更改后的 ...