Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 15

Categorize BMI

Medium

16 minute session

Summary

Compute BMI and return a WHO-style category using conditional logic.

Problem statement

Create a function categorize_bmi(weight_kg, height_m) that computes BMI = weight_kg / (height_m ** 2) and returns one of the strings: - 'Underweight' for BMI < 18.5 - 'Normal weight' for 18.5 <= BMI < 25 - 'Overweight' for 25 <= BMI < 30 - 'Obese' for BMI >= 30 If weight_kg or height_m is non-positive (<= 0), return 'Invalid input'. Use if/elif/else to select the correct category.

Task

Write a function to calculate Body Mass Index (BMI) and categorize it into Underweight, Normal weight, Overweight, or Obese. Handle invalid inputs gracefully.

Examples

Normal weight example

Input

weight_kg=70, height_m=1.75

Output

Normal weight

Explanation

BMI = 70 / 1.75^2 ≈ 22.86, which is between 18.5 and 25.

Input format

Two numbers: weight in kilograms (float or int) and height in meters (float or int).

Output format

Return a string: one of 'Underweight', 'Normal weight', 'Overweight', 'Obese', or 'Invalid input'.

Constraints

Do not use external libraries. Treat non-positive weight or height as invalid.

Samples

Sample input 0

50, 1.8

Sample output 0

Underweight

Explanation 0

BMI ≈ 15.43 -> Underweight.

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

05:10 AM

Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.