目錄python
BMI:對身體質量的刻畫框架
定義:\(BMI = 體重 (kg) / 身高^2 (m^2)\)spa
這個值是否健康呢?code
國際:世界衛生組織 國內:國家衛生健康委員會orm
分類 | 國際BMI值\((kg/m^2)\) | 國內BMI值\((kg/m^2)\) |
---|---|---|
偏瘦 | <18.5 | <18.5 |
正常 | 18.5 ~ 25 | 18.5 ~ 24 |
偏胖 | 25 ~ 30 | 24 ~ 28 |
肥胖 | ≥30 | ≥28 |
-輸入:給定體重和身高值
-輸出:BMI指標分類信息(國際和國內)input
思路方法it
分類 | 國際BMI值\((kg/m^2)\) | 國內BMI值\((kg/m^2)\) |
---|---|---|
偏瘦 | <18.5 | <18.5 |
正常 | 18.5 ~ 25 | 18.5 ~ 24 |
偏胖 | 25 ~ 30 | 24 ~ 28 |
肥胖 | ≥30 | ≥28 |
# CalBMIv1.py 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 = "偏胖" print("BMI 指標爲:國際'{0}'".format(who))
請輸入身高(米)和體重\(公斤)[逗號隔開]: 1.8,70 BMI 數值爲:21.60 BMI 指標爲:國際'正常'
# CalBMIv2.py 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 25 <= bmi < 38: nat = "偏胖" print("BMI 指標爲:國內'{0}'".format(nat))
請輸入身高(米)和體重\(公斤)[逗號隔開]: 1.8,70 BMI 數值爲:21.60 BMI 指標爲:國內'正常'
# CalBMIv3.py 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.8,70 BMI 數值爲:21.60 BMI 指標爲:國際'正常', 國內'正常'
關注多分支條件的組合table