变量练习

小明的成绩从去年的72分提升到今年的85分,请计算小明成绩提升的百分点。并用

字符串格式化显示出'xx.x%',只保留小数点后一位:

s1 = 72
s2 = 85
r = (85-72)/72*100 #小明成绩进步的百分比
print('%.1f%%' % r) #格式化输出xx.x%,保留小数点后一位

使用list和tuple练习

请用索引去出下面list的指定元素:

L = [
['Apple', 'Google', 'Microsoft'],
['Java', 'Python', 'Ruby', 'PHP']
['Adam', 'Bart', 'Lisa']
]
#打印Apple:
print(L[0][0])
#打印Python
print(L[1][1])
#打印Lisa
print(L[2][2])

条件判断练习

小明身高1.75, 体重80.5kg。请根据BMI公式(体重除以身高的平方)帮小明就按

他的BIM指数,并根据BMI指数:

  • 低于18.5: 过低
  • 18.5-25:正常
  • 25-28:过重
  • 28—32:肥胖
  • 高于32:严重肥胖

用if-elif判断并打印结果:

height = 1.75
weight = 80.5
bmi = weight / pow(height,2)
if bmi < 18.5:
print('your weight is too light')
elif bmi > 18.5 and bmi < 25:
print('your weight is normal')
elif bmi > 25 and bmi < 28:
print('your weight is overweight')
elif bmi > 28 and bmi < 32:
print('fat')
else:
print('you are too fat')

循环练习

请利用循环依次对list中的每个名字打印出Hello,xxx!

L = ['Bart', 'Lisa', 'Adam']
for name in L:
print('hello,',name)

调用函数练习

n1 = 255
n2 = 1000
print(hex(n1))
print(hex(n2))

最新文章

  1. 【hive】——Hive初始了解
  2. 使用Cookie实现跨域单点登录的原理
  3. 迭代器iterator
  4. c++11中的static
  5. Dojo学习_组件属性
  6. Centos7 安装MPlayer过程详解
  7. JAVA中集合类的使用
  8. 菜鸟学习Hibernate——配置Hibernate环境
  9. Linux ls -l内容详解
  10. RegisterClientScriptBlock CommandName 模块列 操作完成 提示
  11. Exploring the 7 Different Types of Data Stories
  12. CodeForces 703C Chris and Road
  13. Eslint报错整理与解决方法(持续整理)
  14. Android进阶(二十二)设置TextView文字水平垂直居中
  15. JavaScript(三)
  16. C# Type.GetType 返回NULL 问题解决记录
  17. 莫烦theano学习自修第十天【保存神经网络及加载神经网络】
  18. JAVA学习笔记系列3-JVM、JRE和JDK的区别
  19. 使用sshpass方式实现ssh自动登录
  20. Docker - 常用基础命令

热门文章

  1. react页面跳转
  2. UVA 10491 Cows and Cars (全概率公式)
  3. TTTTTTTTTTT hdu 1520 Anniversary party 生日party 树形dp第一题
  4. C++11 中的强类型枚举
  5. ZOJ - 3780-Paint the Grid Again-(拓扑排序)
  6. 微信小程序_(组件)组件基础
  7. C++入门经典-例3.15-使用do-while循环计算1到10的累加
  8. swift模式和模式匹配
  9. 前端学习框架之layui
  10. P2239 螺旋矩阵