BMI Category
体重指数分类
Same elif chain — but now the technique is monotonic ordering: by going low-to-high, each branch's condition becomes a single upper bound. No and needed.
The thresholds
bmi < 18.5→"Underweight"18.5 <= bmi < 25→"Normal"25 <= bmi < 30→"Overweight"bmi >= 30→"Obese"
The cleanest pattern
Python · runnable
Verbose alternative (also correct)
Defensive — survives someone reordering branches
Check yourself
What does bmi_category(25.0) return with the LOW-TO-HIGH version?
Now you try
Open 02-bmi-category.py. Implement the function — the autograder
runs 7 tests covering each category plus the three boundary values.