How does a program choose a path?
By the end of this lesson
Trace a simple if/else on a marks rule (pass if ≥ 40) and connect it to algebra inequalities.
Remember
- if / else lets a program choose a path.
- The condition is a yes/no question: marks >= 40.
- True → the if block runs. False → the else block runs (if there is one).
- This is the diamond in a flowchart, and the same idea as x ≥ 40 in algebra.
- Indentation (the extra spaces) shows which lines belong to the if.
Worked examples
Cover the answer. Try the steps on paper, then open them.
Example 1 — Pass line
marks = 42 if marks >= 40: print("Pass") else: print("Try again")
- 42 >= 40 is True
- The if branch runs
- Screen: Pass
- else is skipped
Answer: Pass
Check: Change to 38 and it prints Try again.
Example 2 — Umbrella
if raining: take umbrella else: leave it.
- Condition: is it raining?
- Two paths, one run
- The unused path is not a bug — it is the other day
Answer: one path per run
Check: Programs choose; they do not take both.
Example 3 — Connect to algebra
if score >= 40 is the inequality score ≥ 40.
- Same comparison symbols: > < >= <= ==
- Algebra draws it on a line; code jumps to a block
Answer: same comparison, different costume
Check: You already learned the symbols in Algebra starters.
Common mistakes
Slip Using = instead of == in a condition (Python).
Fix = assigns. == asks “equal?”.
if score = 10 is the wrong symbol.
Slip Forgetting else and wondering why nothing printed when the if was false.
Fix A bare if does nothing on the false path.
Add else, or accept silence.
Slip Not indenting the print under the if.
Fix Python uses indent to know the block.
The extra spaces are part of the language.
Try on paper first
Write the answer, then tap Reveal. These are not the quiz — they are warm-ups.
1. What type of question does if ask?
Answer: Yes/no (true/false)
2. If marks = 40 and the test is marks >= 40, do you pass?
Answer: Yes
3. If marks = 39 and the test is marks >= 40, do you pass?
Answer: No
4. The flowchart shape for if is a…
Answer: Diamond
Touch practice
9 tap / typeTap or type. Use the hint if you need it. Retry any miss — the why is the lesson.
Optional picture lab
After practiceReal world
Umbrella if it rains.
Connect
Algebra inequalities: if marks ≥ 40.
⭐ Star quiz
9 questionsDo the worked examples and touch practice first. Then take the quiz without peeking.