Calculate Body Mass Index (BMI)

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

BeginnerTopic: Basic Python Programs
Back

What You'll Learn

  • Using exponentiation for squared values
  • Combining numeric computation with classification logic
  • Applying real-world thresholds in code

Python Calculate Body Mass Index (BMI) Program

This program helps you to learn the fundamental structure and syntax of Python programming.

Try This Code
# 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

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.

Understanding Calculate Body Mass Index (BMI)

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.

Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.