Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

BMI Calculator with Category

Compute BMI from kilograms and meters with Python. Students square height, apply adult cutoffs, and understand why a screening example is not a diagnosis.

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

In this one

  • Keep physical units consistent
  • Square height
  • Interpret screening categories cautiously

How it works

  1. 1

    Read weight in kilograms and height in meters.

  2. 2

    Calculate weight / height ** 2.

  3. 3

    Choose the category from the unrounded BMI and print both.

Edge cases

What unit is expected for height?

What unit is expected for height?

Meters, not centimeters.

What happens at height zero?

What happens at height zero?

The division raises ZeroDivisionError.

What's going on

BMI is weight divided by height squared. Height must be in meters, so entering centimeters directly gives a very different and incorrect result.

The ordered comparisons classify the numeric BMI using the stated cutoffs. .2f rounds only the display, not the value used for categorization. Height zero raises division by zero. This adult-oriented classroom rule is a screening example, not a diagnosis or a child growth assessment.

What unit is expected for height? Meters, not centimeters.

What happens at height zero? The division raises ZeroDivisionError.

Quiz

Tap an option. The answer stays hidden until you pick.

Question 1

Which expression squares height?

Pick an answer to check it.

Question 2

What unit is expected for height?

Pick an answer to check it.

Questions people ask

What unit is expected for height?

Meters, not centimeters.

What happens at height zero?

The division raises ZeroDivisionError.

Which expression squares height?

height ** 2.