Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Categorize BMI

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

Python practice16 minControl Flow (If–Else Logic)IntermediateLast updated March 15, 2026

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

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 1

Input

50, 1.8

Output

Underweight

BMI ≈ 15.43 -> Underweight.