python3—廖雪峰之练习(一)
2024-10-07 02:11:44
变量练习
小明的成绩从去年的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))
最新文章
- 【hive】——Hive初始了解
- 使用Cookie实现跨域单点登录的原理
- 迭代器iterator
- c++11中的static
- Dojo学习_组件属性
- Centos7 安装MPlayer过程详解
- JAVA中集合类的使用
- 菜鸟学习Hibernate——配置Hibernate环境
- Linux ls -l内容详解
- RegisterClientScriptBlock CommandName 模块列 操作完成 提示
- Exploring the 7 Different Types of Data Stories
- CodeForces 703C Chris and Road
- Eslint报错整理与解决方法(持续整理)
- Android进阶(二十二)设置TextView文字水平垂直居中
- JavaScript(三)
- C# Type.GetType 返回NULL 问题解决记录
- 莫烦theano学习自修第十天【保存神经网络及加载神经网络】
- JAVA学习笔记系列3-JVM、JRE和JDK的区别
- 使用sshpass方式实现ssh自动登录
- Docker - 常用基础命令