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.
1# Take inputs2weight = float(input("Enter weight (kg): "))3height = float(input("Enter height (m): "))45# Calculate BMI6bmi = weight / (height ** 2)78# Categorize9if bmi < 18.5:10 category = "Underweight"11elif bmi < 25:12 category = "Normal"13elif bmi < 30:14 category = "Overweight"15else:16 category = "Obese"1718print(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
Read weight in kilograms and height in meters.
- 2
Calculate weight / height ** 2.
- 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.
๐Related Content
- ๐
Phase 6 - Learn Concepts
Review Phase 6 concepts and explanations
- ๐
Phase 6 - Quiz
Test your Phase 6 understanding with quiz questions
- ๐ป
Phase 6 - All Practice Problems
Explore all practice problems for Phase 6
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum