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