Program for calculating body mass index (BMI)

Python Methods and Functions

Index body mass (BMI) or Quetelet index — it is a value derived from the mass (weight) and height of a person, man or woman. BMI is defined as body weight divided by the square of height and is expressed universally in units of kg / m2 as a result of weight in kilograms and height in meters. Formula:

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

Examples:

 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) 

# Python program for illustration
# how to calculate BMI

def BMI (height, weight):

bmi = weight / (height * * 2 )

return bmi

 
  # Driver code

height = 1.79832

weight = 70

  
# call BMI function

bmi = BMI (height, weight)

print ( "The BMI is" , format (bmi), "so " , end = ` `)

 
# Conditions to check the BMI category

if (bmi & lt;  18.5 ):

  print ( "underweight" )

 

elif (bmi & gt; = 18.5 and bmi & lt; 24.9 ):

print ( "Healthy" )

 

elif (bmi & gt; = 24.9 and bmi & lt; 30 ):

print ( " overweight " )

 

elif (bmi & gt ; = 30 ):

print ( " Suffering from Obesity " )

Output:

 The BMI is 21.64532402096181 so Healthy 




Get Solution for free from DataCamp guru