Calculate Body Mass Index (BMI)

Calculate BMI from weight (kg) and height (meters) and classify the result.

PythonBeginner

What You'll Learn

  • Using exponentiation for squared values
  • Combining numeric computation with classification logic
  • Applying real-world thresholds in code
Python
# Program to calculate Body Mass Index (BMI)

weight = float(input("Enter your weight in kg: "))
height = float(input("Enter your height in meters: "))

if height <= 0:
    print("Height must be greater than zero.")
else:
    bmi = weight / (height ** 2)
    print("Your BMI is:", round(bmi, 2))

    if bmi < 18.5:
        print("Category: Underweight")
    elif bmi < 25:
        print("Category: Normal weight")
    elif bmi < 30:
        print("Category: Overweight")
    else:
        print("Category: Obesity")

Output

Enter your weight in kg: 68
Enter your height in meters: 1.75
Your BMI is: 22.2
Category: Normal weight

BMI is calculated as:

[ BMI = \frac{\text{weight}}{\text{height}^2} ]

Then we classify based on standard thresholds:

  • < 18.5 → Underweight
  • 18.5–24.9 → Normal weight
  • 25–29.9 → Overweight
  • ≥ 30 → Obesity

This program combines arithmetic, conditional logic, and basic validation.

Step-by-Step Breakdown

  1. 1Read weight and height from the user.
  2. 2Validate that height is positive.
  3. 3Compute BMI as weight / (height ** 2).
  4. 4Round and print the BMI value.
  5. 5Use if-elif-else to print the BMI category.