📜  计算体重指数 (BMI) 的程序

📅  最后修改于: 2022-05-13 01:54:19.301000             🧑  作者: Mango

计算体重指数 (BMI) 的程序

体重指数 (BMI)Quetelet 指数是从个体(男性或女性)的质量(体重)和身高得出的值。 BMI 定义为体重除以身高的平方,通常以 kg/m2 为单位表示,由以千克为单位的质量和以米为单位的身高得出。公式为:

BMI = (mass or weight)/(height*height)
where,
mass or weight is in Kg,
height is in meters

例子:

Input : height(in meter): 1.79832
weight(in Kg): 70
Output : The BMI is 21.64532402096181, so Healthy.
Explanation : 70/(1.79832*1.79832)

Input : height(in meter): 1.58496
weight(in Kg): 85
Output : The BMI is 33.836256857260594 so Suffering from Obesity
Explanation : 70/(1.58496*1.58496)

Python3
#Python program to illustrate
# how to calculate BMI
def BMI(height, weight):
    bmi = weight/(height**2)
    return bmi
 
# Driver code
height = 1.79832
weight = 70
 
# calling the BMI function
bmi = BMI(height, weight)
print("The BMI is", format(bmi), "so ", end='')
 
# Conditions to find out BMI category
if (bmi < 18.5):
    print("underweight")
 
elif ( bmi >= 18.5 and bmi < 24.9):
    print("Healthy")
 
elif ( bmi >= 24.9 and bmi < 30):
    print("overweight")
 
elif ( bmi >=30):
    print("Suffering from Obesity")


输出:

The BMI is 21.64532402096181 so Healthy