
Last Updated on 16 March 2025
Body Mass Index (BMI) is a numerical value calculated based on a person’s weight and height. It helps determine whether a person is underweight, normal weight, overweight, or obese.
BMI Formula:
\[\text{BMI} = \frac{\text{weight (kg)}}{\text{height (m)}^2}\]In this tutorial, we will write a Python program to calculate BMI and classify the result into different categories.
Python Program to Calculate BMI
# Taking user input
weight = float(input("Enter your weight in kg: "))
height = float(input("Enter your height in meters: "))
# Calculating BMI
bmi = weight / (height ** 2)
# Determining BMI category
if bmi < 18.5:
category = "Underweight"
elif 18.5 <= bmi < 24.9:
category = "Normal weight"
elif 25 <= bmi < 29.9:
category = "Overweight"
else:
category = "Obese"
# Displaying the results
print(f"Your BMI is: {bmi:.2f}")
print(f"Category: {category}")
Output
Enter your weight in kg: 60 Enter your height in meters: 1.76784 Your BMI is: 19.20 Category: Normal weight