内容正文:
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
少儿编程课
1
BMI计算器
2
if条件语句
x=6
if x%2==0:
print(x,"是偶数")
else:
print(x,"是奇数")
3
if多重条件语句
代码结构
if … :
…
elif … :
…
elif … :
…
4
if条件语句应用
x = 0
if x > 0:
print(x, "是正数")
elif x < 0:
print(x, "是负数")
elif x == 0:
print(x, "是零")
代码实现
if多重条件语句
代码结构
if … :
…
elif … :
…
elif … :
…
else … :
…
转换指令
将字符串转换为数值(小数):float()
score=input("请输入数学成绩:")
score=float(score)
print(score)
成绩判断
score=input("请输入数学成绩:")
score=float(score)
if score>=90:
print("A")
elif score>=80:
print("B")
elif score>=70:
print("C")
else:
print("D")
BMI指数
BMI指数(即身体质量指数,简称体质指数又称体重,英文为Body Mass Index,简称BMI),是用体重公斤数除以身高米数平方得出的数字,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。
分析BMI计算器
除法符号 : /
height=1.6
weight=51
num=weight/pow(height,2)
print(num)
求次幂指令:pow(数值,次幂)
实现BMI计算器
weight = input("你的体重是多少kg?")
weight=float(weight)
height =input("你的身高是多少m?")
height=float(height)
bmi = weight/pow(height,2)
print(bmi)
11
实现BMI计算器
if bmi <=18.4:
print("偏瘦")
elif bmi < 23.9:
print("正常")
elif bmi < 27.9:
print("过重")
elif bmi>=28:
print("肥胖")
12
$$