BMI Calculator with Category

Calculate BMI and categorize.

IntermediatePhase 6 - Category 5: Real-World Logic ProblemsExample 3 of 15
bmi-calculator-with-category.py
1# Take inputs
2weight = float(input("Enter weight (kg): "))
3height = float(input("Enter height (m): "))
4
5# Calculate BMI
6bmi = weight / (height ** 2)
7
8# Categorize
9if bmi < 18.5:
10 category = "Underweight"
11elif bmi < 25:
12 category = "Normal"
13elif bmi < 30:
14 category = "Overweight"
15else:
16 category = "Obese"
17
18print(f"BMI: {bmi:.2f}")
19print(f"Category: {category}")

Output

Enter weight (kg): 70
Enter height (m): 1.75
BMI: 22.86
Category: Normal

What's going on

Calculate BMI and assign category.

Key Concepts:

BMI = weight / height²
Check ranges for categories
Use elif chain