【MOOC嵩天Python语言程序设计】4.2 实例5:身体质量指数BMI

height, weight = eval(input("请输入身高(米)和体重(公斤)[逗号隔开]:"))
bmi = weight / pow(height, 2)
print("BMI数值为:{:.2f}".format(bmi))
who = ""
if bmi < 18.5:
    who = "偏瘦"
elif 18.5 <= bmi < 25:
    who = "正常"
elif 25 <= bmi < 30:
    who = "偏胖"
else:
    who = "肥胖"
print("BMI 指标为:国际'{0}'".format(who))


请输入身高(米)和体重(公斤)[逗号隔开]1.75,74
BMI数值为:24.16
BMI 指标为:国际'正常'





height, weight = eval(input("请输入身高(米)和体重(公斤)[逗号隔开]:"))
bmi = weight / pow(height, 2)
print("BMI数值为:{:.2f}".format(bmi))
nat = ""
if bmi < 18.5:
    nat = "偏瘦"
elif 18.5 <= bmi < 24:
    nat = "正常"
elif 24 <= bmi < 28:
    nat = "偏胖"
else:
    nat = "肥胖"
print("BMI 指标为:国内'{0}'".format(nat))


请输入身高(米)和体重(公斤)[逗号隔开]1.75,71
BMI数值为:23.18
BMI 指标为:国内'正常'





height, weight = eval(input("请输入身高(米)和体重(公斤)[逗号隔开]:"))
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 指标为:国际'{0}', 国内'{1}'".format(who, nat))


请输入身高(米)和体重(公斤)[逗号隔开]1.75, 74
BMI数值为:24.16
BMI 指标为:国际'正常', 国内'偏胖'

猜你喜欢

转载自blog.csdn.net/vanarrow/article/details/106970169