Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
PYTHON FOUNDATIONS / CHAPTER 01 / Learn / LESSON 05
Fourth class. The BMI number alone is dry. People want a label: underweight, normal, overweight, obese.
This is where conditions come in. if checks whether something is true. If not, elif offers the next test. else is “in all remaining cases”. Python uses indentation instead of braces: the branch body is shifted inward.
Thresholds in this lesson: - below 18.5 → underweight - below 25 → normal - below 30 → overweight - otherwise → obese
Order matters. If you first ask bmi < 30, “normal” values also fall there. So we walk from the tighter threshold to the wider one.
Mini example:
x = 20
if x < 18.5:
label = "underweight"
elif x < 25:
label = "normal"
else:
label = "other"
print(label)With the lesson data BMI ≈ 23.15, so we expect "normal". Labels are lowercase English — exactly as the lab checks them.
Common mistake: scrambled elif order or a different string ("Normal" instead of "normal").
Conditions pick a branch. For the test data BMI ≈ 23.15 → category should be "normal".
DECISION STANDBY
›