一、运算符

% 取模,返回商的余数

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('编号输入错误')

  

最新文章

  1. SQLServer中Partition By 函数的使用
  2. AsyncTask 异步处理
  3. mysql创建新用户并分配数据库权限
  4. Android 隐式意图激活另外一个Actitity
  5. sp_getTable_data
  6. 【maven】解决Missing artifact jdk.tools:jdk.tools:jar:1.6
  7. python jinjia2模板使用
  8. Symfony2学习笔记之数据库操作
  9. debian分区方案(就这个看着靠谱点)转
  10. 浅析nginx的负载均衡
  11. [转]WinForm如何调用Web Service
  12. PhoneGap 开发笔记
  13. Google Earth数据存储、管理、表现及开发机制
  14. 电梯调度编写(oo-java编程)
  15. [漏洞分析]thinkphp 5.x全版本任意代码执行分析全记录
  16. wamp多站点多端口配置
  17. eclipse安装spring boot插件spring tool suite
  18. 用SQL命令手工创建CDB
  19. jquery禁用form表单中的文本框
  20. HTML知识基础

热门文章

  1. CAS 跨域原理
  2. MVC Html.AntiForgeryToken() 防止CSRF攻击 - CSDN博客
  3. iOS App 项目:会员卡管理系统设计方案
  4. JavaScript 层
  5. UVA - 11178-Morley’s Theorem
  6. 微信小程序 项目实战(二)board 首页
  7. candy——动态规划
  8. 如何在List集合中去重
  9. 【转载】关于Hash
  10. 依据iPhone6设计稿动态计算rem值