Represent quantities before calculating
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.
Represent quantities before calculating
A variable name binds a value used by later statements; assignment changes that binding. In Python, cost = cost + 5 evaluates the old value, adds five, then binds the result. It is not a mathematical equation asserting cost equals itself plus five. A named constant such as PENCE_PER_POUND communicates intent, but uppercase spelling does not prevent Python reassignment. Integer, real, Boolean, character and string are useful specification categories. Python represents a character as a string of length one; it has no separate character type. Entry skills are lesson 1 contracts and decimal place value.
Types and units answer different questions. Both duration_seconds and cost_pence can be integers, yet adding them makes no meaningful quantity. A string such as "12" is text: joining it to "3" gives "123", whereas converting both to integers and adding gives 15. A Boolean represents a decision with two truth values. A Python float approximates real-number arithmetic; many finite decimal fractions cannot be represented exactly in binary. This is why our small cost model stores whole pence rather than accumulating decimal pounds. It is a modelling choice with a stated rounding policy, not a universal solution to financial calculation.
A bicycle hire kiosk charges 125 pence per started 15-minute block. Separate conversion, arithmetic and output. Duration is a non-negative whole number of minutes supplied to a pure function. quotient and remainder identify complete blocks and a partial block. Exactly zero minutes costs zero; exactly 15 minutes costs one block; 16 costs two. Real division / would return a float and would not itself decide how to charge partial blocks. Integer division // and remainder % encode that decision for these non-negative values. Negative operands need special care: Python // rounds down, so -7 // 3 is -3 and -7 % 3 is 2, not the truncated quotient some pseudocode conventions use.
Keyboard input is untrusted text and input() returns a string. A complete interactive boundary might use int(input("Minutes: ")), catch a conversion failure and display a helpful message. The runnable example below keeps the calculation pure and prints fixed fictional values so tests do not block for keyboard input. Formatting with // and % splits pence into pounds and leftover pence. A two-digit format preserves the display of £2.05. A valid numeric conversion is only one layer of validation: -20 can be converted successfully but violates the business rule.
A test must challenge the charging policy, not merely repeat a happy-path printout. Predict outputs immediately below, on and above a block boundary. Explain whether a requested discount acts per block or on the final bill before changing code. The binary visual reminds us that stored numbers have representations, but Python integers are not automatically eight-bit counters. The next lessons make these contracts executable and connect representations to comparison and control flow.
Runnable original Python 3 example (also saved verbatim in examples for CLI execution):
```python
PENCE_PER_BLOCK = 125
MINUTES_PER_BLOCK = 15
def hire_cost(minutes):
"""Return whole pence; minutes is an integer >= 0."""
if minutes < 0:
raise ValueError("negative duration")
blocks = minutes // MINUTES_PER_BLOCK
if minutes % MINUTES_PER_BLOCK:
blocks += 1
return blocks * PENCE_PER_BLOCK
def money(pence):
return f"£{pence // 100}.{pence % 100:02d}"
assert [hire_cost(n) for n in (0, 14, 15, 16)] == [0, 125, 125, 250]
assert money(205) == "£2.05"
print(money(hire_cost(31)))
```
Worked example: Find the charge and display for 31 minutes.
31 // 15 is 2; 31 % 15 is 1.
The partial block makes three started blocks.
3 × 125 = 375 pence; pounds are 3 and remainder pence 75.
Answer: £3.75.
Check your understanding: Transfer: a five-minute free allowance is applied before charging. Give results for 4, 5, 6, 20 and 21 minutes; propose a safe expression and say what happens to input "5.5".
Answer: Adjusted minutes = max(0, minutes - 5). Charges in pence are 0, 0, 125, 125, 250. Pass the adjusted value to hire_cost. int("5.5") raises ValueError; either reject fractional input or explicitly define a different duration and rounding contract.
Why: The free allowance must precede rounding into blocks. Subtracting a fixed cash discount after charging is a different policy. Refusing silent truncation protects the meaning of units and avoids hidden undercharging.