python学习笔记四(2)--身体质量指数BMI

一、需求分析

1、输入:给定体重和身高
#接收用户的两个输入
2、输出:BMI分类指标(国际和国内)
#处理国际和国内指标的不同

#单个国际标准
weight,height=eval(input("请输入体重(kg)和身高(m)[用逗号隔开】:"))
BMI=weight/pow(height,2)
if BMI<18.5:
    print("偏瘦")
elif 18.5<=BMI<25:
    print("正常")
elif 25<=BMI<30:
    print("偏胖")
else:
    print("肥胖")
#单个国际标准备注及BMI数值展示
weight,height=eval(input("请输入体重(kg)和身高(m)[用逗号隔开】:"))
BMI=weight/pow(height,2)
who=""
#设置变量,之后统一对变量进行输出
if BMI<18.5:
    who="偏瘦"
elif 18.5<=BMI<25:
    who="正常"
elif 25<=BMI<30:
    who="偏胖"
else:
    who="肥胖"
print("BMI指标为:{}国际:'{}'.format(BMI,who))

#Ca1BMIV1.py
weight,height=eval(input("请输入体重(kg)和身高(m)[用逗号隔开】:"))
BMI=weight/pow(height,2)
who,nat="",""
#将国际和国内的区分开
if BMI<18.5:
    who, nat = "偏瘦", "偏瘦"
elif 18.5<=BMI<24:
    who, nat = "正常", "正常"
elif 24<=BMI<25:
    who, nat = "正常", "偏胖"
elif 25<=BMI<28:
    who, nat = "偏胖", "偏胖"
elif 28<=BMI<30:
    who, nat = "偏胖", "肥胖"
else:
    who, nat = "肥胖", "肥胖"
print("BMI指标为{}:国际'{}',国内'{}'".format(BMI,who,nat))

请输入体重(kg)和身高(m)[用逗号隔开】:55,1.55
BMI指标为22.892819979188342:国际正常,国内正常
#Ca1BMIV1.py
weight,height=eval(input("请输入体重(kg)和身高(m)[用逗号隔开】:"))
BMI=weight/pow(height,2)
print("BMI数值为:{:.2f}".format(BMI))
who,nat="",""
if BMI<18.5:
    who, nat = "偏瘦", "偏瘦"
    #设置变量,之后统一对变量进行整理、输出
elif 18.5<=BMI<24:
    who, nat = "正常", "正常"
elif 24<=BMI<25:
    who, nat = "正常", "偏胖"
elif 25<=BMI<28:
    who, nat = "偏胖", "偏胖"
elif 28<=BMI<30:
    who, nat = "偏胖", "肥胖"
else:
    who, nat = "肥胖", "肥胖"
print("BMI指标为:国际'{}',国内'{}'".format(who,nat))

请输入体重(kg)和身高(m)[用逗号隔开】:55,1.55
BMI数值为:22.89
BMI指标为:国际'正常',国内'正常'

你可能感兴趣的:(python学习笔记四(2)--身体质量指数BMI)