Comparisons and decisions with boundaries
By UK GCSE Computer Science · independent study · myAudience

Original AI-generated teaching raster via built-in image_gen; author inspected 2026-10-04. · Generated project artwork; no copied exam or publisher illustration. Independent rights/publication review pending.
Comparisons and decisions with boundaries
A selection chooses which statements to execute from a condition. In Python, = assigns and == compares; confusing them either causes a syntax error in an ordinary if condition or expresses the wrong operation elsewhere. Comparisons <, >, <=, >=, == and != produce Boolean results for our numeric inputs. A fictional parcel service labels masses below 500 grams “small”, from 500 through 1999 grams “medium”, and from 2000 through 5000 grams “large”. Masses outside 1–5000 are invalid. Entry skills are typed quantities and integer units. The ordering and inclusivity of thresholds belong to the algorithm, not to indentation style.
A single if/elif/else chain evaluates decisions in order and selects the first true branch. After validating the range, mass < 500 is sufficient for small. If that condition is false we already know mass >= 500, so mass < 2000 means medium. Repeating every lower bound is unnecessary but may be helpful in an independent Boolean expression. Three independent if statements can overwrite a label if the conditions overlap; indentation can also put a return inside the wrong block. A trace table should show both the condition result and the selected branch, not just the final label.
Compound conditions combine decisions. AND requires both, OR permits either, and NOT reverses a Boolean. Parentheses make intended grouping explicit. For example valid = (mass >= 1) and (mass <= 5000) states the inclusive range. invalid = (mass < 1) or (mass > 5000) is its complement; replacing or with and makes an impossible condition and allows every invalid value through. Nested selection can express an extra decision within a mass band, such as applying an oversize check only to a large parcel. It must not accidentally apply the outer condition to all subsequent statements.
Test data must discriminate nearby policies. Values 499 and 500 expose < versus <= at the first boundary; 1999 and 2000 expose the second. Values 0 and 5001 test the rejection rule. Ordinary data such as 250, 800 and 3000 checks each band but cannot locate an off-by-one error alone. Calling a value “boundary” is not a justification: specify which boundary it challenges and the predicted result. Validation is about conformance to this contract, not verification that a measurement is true; a plausible 700-gram value could still be a mistaken reading.
The generated Boolean composition visual supports combining conditions, while its letters do not stand for parcel categories. Explain any mapping you use. A demand such as “large if heavy or oversize” may produce overlapping categories; resolve priority in prose before coding. Later truth tables let us systematically enumerate decisions, but threshold ranges are often best explained with ordered intervals and concrete counterexamples.
Runnable original Python 3 example (also saved verbatim in examples for CLI execution):
```python
def parcel_band(mass_g):
"""Classify integer grams, rejecting outside 1..5000."""
if not 1 <= mass_g <= 5000:
raise ValueError("mass outside supported range")
if mass_g < 500:
return "small"
elif mass_g < 2000:
return "medium"
else:
return "large"
assert [parcel_band(x) for x in (1, 499, 500, 1999, 2000, 5000)] == [
"small", "small", "medium", "medium", "large", "large"]
```
Worked example: Trace 2000 grams and identify a counterexample to using <= 2000 for medium.
Range check succeeds because 2000 lies in 1..5000.
2000 < 500 is false and 2000 < 2000 is false.
The else branch returns large. With <= 2000, the same value would incorrectly return medium.
Answer: Large; 2000 is the discriminating counterexample.
Check your understanding: Transfer: mass is valid and either length <= 40 cm OR a special rigid box is used. Construct the acceptance expression; show why mass-valid AND length-valid OR rigid-box can be unsafe.
Answer: accept = mass_valid and (length_valid or rigid_box). The unparenthesised Python expression groups AND first; with mass_valid=False, length_valid=False, rigid_box=True it accepts an invalid mass.
Why: A counterexample tests a semantic security boundary. A branch being reachable does not mean it is correct. The grouped policy makes valid mass mandatory regardless of packaging.