【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 指標爲:國際'正常', 國內'偏胖'
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章