Learning route
Turn a rule into a decision. Prove that every boundary works.
Prerequisite: Can assign variables, use input(), convert a whole-number input with int(), and run a Python file.
- Translate a written rule into an if / elif / else structure.
- Trace comparisons and Boolean conditions accurately.
- Choose test values immediately below, on and above a threshold.
- Repair a decision and explain why the change is correct.
Retrieve and explain
- What data type does input() return, even when the user enters 12?
- Write a statement that reads an age as an integer.
- Predict the final value: score = 8, then score = score + 2.
- Which expression compares values: age = 12 or age == 12?
A condition evaluates to True or False. Selection chooses which block runs. In one if / elif / else chain, Python runs the first matching branch and skips the rest of that chain. Indentation defines each block.
score = 68
if score >= 70:
print("Distinction")
elif score >= 50:
print("Pass")
else:
print("Retry")
The result is Pass. At the second condition, we already know that the score is below 70. The code therefore covers 50–69 without repeating the upper bound.
| Python | Meaning | Example |
|---|---|---|
| == / != | Equal / not equal | score == 50 |
| < / <= | Less than / at most | age < 12 |
| > / >= | Greater than / at least | score >= 70 |
| and | Both conditions must be true | age >= 12 and age <= 17 |
| or | At least one condition must be true | age < 0 or age > 120 |
| not | Reverses a Boolean result | not booked |
One chain or separate decisions?
Two separate if statements can both run. Use a chain for mutually exclusive categories. The line after the chain, at its original indentation, runs regardless of which branch was taken.
Worked example
A parcel service accepts whole-number masses from 1 to 20 kg. Masses up to 5 kg cost £4; masses above 5 kg cost £7. Anything outside 1–20 kg produces Invalid mass.
mass = int(input("Mass in kg: "))
if mass < 1 or mass > 20:
print("Invalid mass")
elif mass <= 5:
print("Charge: 4")
else:
print("Charge: 7")
| Input | First condition | Second condition | Output |
|---|---|---|---|
| 5 | False | True | Charge: 4 |
| 6 | False | False | Charge: 7 |
| 21 | True | Not evaluated | Invalid mass |
The invalid-data branch comes first, so elif mass <= 5 cannot accidentally accept zero or a negative mass. Predict mass 1 before opening the trace lab.
Repair practice
A club accepts integer ages 12–17 inclusive. Repair the code, then test ages 11, 12, 17 and 18. Record each expected output before running it.
age = int(input("Age: "))
if age >= 12 or age <= 17:
print("Eligible")
else:
print("Not eligible")
Explain why the original condition admits age 10. Then decide whether 12 <= age <= 17 expresses the same rule as your repair.
Repair feedback
age = int(input("Age: "))
if age >= 12 and age <= 17:
print("Eligible")
else:
print("Not eligible")
The original or condition is true for every integer: ages below 12 satisfy the second comparison and ages above 17 satisfy the first. With and, both limits must hold. The chained comparison is equivalent. Expected results: 11 → Not eligible; 12 → Eligible; 17 → Eligible; 18 → Not eligible.
Independent practice
Independent build: activity tickets. An activity accepts integer ages from 0 to 120. Ages below 12 pay £5; ages 12–17 pay £8; ages 18–120 pay £12. Outside the valid range, output Invalid age and no price.
- Read the age as an integer.
- Reject ages outside 0–120.
- Output exactly one price, labelled Price:, for a valid age.
- Write expected results for −1, 0, 11, 12, 17, 18, 120 and 121, then run the tests.
Assume the user enters a whole number. Use one decision chain. Keep your own test record as evidence.
# Proof Academy | Lesson 01 | Activity tickets
# Input is a whole number. Valid ages: 0 to 120 inclusive.
# Under 12: 5 pounds; 12-17: 8 pounds; 18+: 12 pounds.
# Your task: read an integer age.
# Your task: reject an invalid age, otherwise output one labelled price.
# Your task: test -1, 0, 11, 12, 17, 18, 120, 121.
Model program and marking guidance
# Proof Academy | Lesson 01 | Worked solution
age = int(input("Age: "))
if age < 0 or age > 120:
print("Invalid age")
elif age < 12:
print("Price: 5")
elif age < 18:
print("Price: 8")
else:
print("Price: 12")
- Reads and converts the age to an integer. [1]
- Rejects both below 0 and above 120; does not output a price for these. [1]
- Correct £5 branch for ages 0–11. [1]
- Correct £8 branch for ages 12–17. [1]
- Correct £12 branch for ages 18–120. [1]
- Outputs one labelled price for each valid input. [1]
- Records correct expected results for all eight supplied boundary tests. [1]
- Runs all eight tests and records actual results; repairs any mismatch. [1]
Exam practice
Original Proof Academy practice · 6 marks. The intended rule is: scores 80 or above receive Gold; scores 50–79 receive Silver; lower scores receive Bronze. Assume a valid integer score from 0 to 100.
score = 85
if score >= 50:
print("Silver")
elif score >= 80:
print("Gold")
else:
print("Bronze")
- State the output for score 85. [1]
- Explain why the intended Gold result is never reached. [2]
- Write a corrected decision chain. [2]
- Give the smallest score that should output Gold. [1]
Worked feedback
1: Silver (1). 2: 85 satisfies the first condition (1); all scores ≥80 also satisfy ≥50, so the elif is skipped whenever Gold is needed (1). 3: check ≥80 first (1), then ≥50 with Bronze as the remaining case (1). 4: 80 (1).
if score >= 80:
print("Gold")
elif score >= 50:
print("Silver")
else:
print("Bronze")
Accept an equivalent solution with explicit non-overlapping ranges. This is a logic error: the original program runs but implements the rule incorrectly.
Homework and feedback
30 minutes: 5 minutes retrieval, 15 minutes coding, 10 minutes testing and explanation.
Write a library loan checker. Assume an integer number of days from 0 to 60. For 0–14 output On time; 15–30 output Reminder; 31–60 output Contact library. Outside 0–60 output Invalid days. Test −1, 0, 14, 15, 30, 31, 60 and 61. Explain the order of your conditions.
Homework feedback
days = int(input("Days: "))
if days < 0 or days > 60:
print("Invalid days")
elif days <= 14:
print("On time")
elif days <= 30:
print("Reminder")
else:
print("Contact library")
Expected outputs in test order: Invalid days; On time; On time; Reminder; Reminder; Contact library; Contact library; Invalid days. Invalid values are removed first; each later band relies on the earlier comparisons being false. Ask for a rewrite from memory if the learner copied without explaining.
Sources and further practice
This chapter is written for Pearson Edexcel GCSE Computer Science 1CP2. Use the specification references in the chapter heading to locate the relevant requirements. Practice questions and point allocations on this page are original Proof Academy teaching material unless a question is explicitly identified as a sourced past-paper bridge.
- Pearson Edexcel 1CP2 specification
- PMT Paper 1 papers and mark schemes
- PMT Paper 2 papers and mark schemes
When using an original paper, open its matching mark scheme and supplied coding files where required. Use that paper's instructions and marks. A short classroom exercise is not a substitute for a full official task.
Trace lab · inline, no inner scroll
Parcel charges
Predict each output, then reveal it. The trace stays in the page.
Keep your evidence
Export your notes before changing devices.
Notes stay in this browser. The Quiz tab records the chapter check, and Resources holds the long-answer questions.