Categorizing BMI
Create a function that categorizes a person’s Body Mass Index (BMI) into "Underweight", "Normal", "Overweight", or "Obese". The criteria are as follows:
- Invalid BMI: BMI < 0
- Underweight: BMI < 18.5
- Normal: 18.5 <= BMI < 25
- Overweight: 25 <= BMI < 30
- Obese: BMI >= 30
Each band ends where the next one begins, so every value from 0 upwards falls in exactly one band.
def categorize_bmi(bmi: float) -> str:
raise NotImplementedError("Replace this line with your code.")
# Inside a band
got = categorize_bmi(22.5)
assert got == "Normal", f"22.5: expected 'Normal', got {got!r}"
# At the bottom of each band
got = categorize_bmi(18.5)
assert got == "Normal", f"18.5: expected 'Normal', got {got!r}"
got = categorize_bmi(25)
assert got == "Overweight", f"25: expected 'Overweight', got {got!r}"
got = categorize_bmi(30)
assert got == "Obese", f"30: expected 'Obese', got {got!r}"
# Just below a boundary, including a value between 24.9 and 25
got = categorize_bmi(24.9)
assert got == "Normal", f"24.9: expected 'Normal', got {got!r}"
got = categorize_bmi(24.95)
assert got == "Normal", f"24.95: expected 'Normal', got {got!r}"
# Below every band
got = categorize_bmi(17)
assert got == "Underweight", f"17: expected 'Underweight', got {got!r}"
# Invalid input
got = categorize_bmi(-5)
assert got == "Invalid BMI", f"-5: expected 'Invalid BMI', got {got!r}"
# Your case: which BMI is most likely to break it?
# got = categorize_bmi(___)
# assert got == "___", f"___: expected '___', got {got!r}"