Python program to calculate BMI

In this article, we are going to learn how to calculate the Body Mass Index (BMI) using Python. Body Mass Index is also known as the Quetelet Index. It is a value calculated using the weight(in Kg) and height(in meter) of a particular person whether male or female. BMI is defined as the body mass upon the square of the body height. The unit of BMI is Kg/m2.

The BMI is calculated to distinguish whether the person is Underweight, Normal weight, Overweight or Obese. A table is given below which contains the data about the above 4 categories.

BMI Weight Status
Below 18.5 Underweight
18.5 – 24.9 Normal or Healthy Weight
25.0 – 29.9 Overweight
30.0 and Above Obese

BMI is calculated using the following formula:-

BMI = [mass/(height*height)]

where, mass = mass of the body in Kg, height = height of body in meter.

Calculation of BMI in Python

Let’s understand with some examples:-

Example 1:-

def BMI(height, weight): 
  bmi = weight/(height**2) 
  return bmi 

height = 1.6616
weight = 57

bmi = BMI(height, weight) 
print("The BMI is", format(bmi))

print("Health status = ",end="")
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")

Output:-

The BMI is 20.645332827684463
Health status = Healthy

We calculated the BMI using the above formula and the BMI lies in the category of the Healthy so the health status is healthy.

Example 2:-

height = 1.82
weight = 105

bmi = round(weight/(height**2),1)

print("The BMI is", bmi)

print("Health status = ",end="")
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")

Output:-

The BMI is 31.7
Health status = Suffering from Obesity

In this example, we did the same thing as we have done in the previous example, the only new thing we added to this example is rounded the BMI to the first place of the nearest integer, and in this example, the output of the BMI lies in the Obesity category so the health status is suffering from Obesity.

Also read:

Leave a Reply

Your email address will not be published. Required fields are marked *