Lesson
Selection with if, elif and else
A PRIMM lesson on choosing between outcomes and tracing which branch runs.
Open a shared Python workspace in seconds.
Lesson overview
- Topic
- Selection
- Level
- GCSE
- Learning objective
- Trace a selection program and explain why one branch runs while the others are skipped.
1.Predict
Example code
score = 64
if score >= 70:
print("Merit")
elif score >= 50:
print("Pass")
else:
print("Keep practising")- Which message will this program print when score = 64?
- Which condition is checked first, and why does that matter?
2.Run
Run the code in Paired, then try changing the score to see which branch runs next.
3.Investigate
- The conditions are checked from top to bottom.
- Only the first matching branch runs, so order matters.
- Why does score = 64 print Pass and not Merit?
- What score would make the else branch run?
4.Modify
- Add a new Distinction outcome for scores of 90 or more.
- Change the messages so they give fuller feedback to the learner.
5.Make
Write your own grade checker using at least three outcomes and sensible score boundaries.
Extension
Add one more boundary and justify where it should appear in the order of the conditions.
Need extra support?
Reece offers GCSE & A-Level Computer Science tutoring: reece-tutoring.co.uk