Start with a calculation you can explain
A program is a precise sequence of instructions. Before writing Python, decide what information enters the program, what processing happens and what result should leave it. A correct-looking screen is not enough: the result must satisfy the rule for the inputs you were given.
A minibus company charges a fixed booking fee of £6 and £4 for each passenger. The program receives a whole-number passenger count. Its processing is 6 + passengers * 4. Its output is a labelled total. Keep pounds as whole numbers for this example; money with pence can instead be represented as an integer number of pence to avoid rounding surprises.
By the end of this chapter, you should be able to choose a type, read and convert input, evaluate an expression, explain assignment and record a meaningful test. Spend 10 minutes predicting expressions, 25 on the explanations and worked programs, 25 building, 15 checking and 15 reviewing your evidence.
Before starting, predict 3 + 4 * 2, explain what the quotation marks mean in "12", and describe the difference between displaying a value and storing it. Keep your predictions; you will revisit them after running a program.
Values, names and types
A variable is a name associated with a value. Assignment evaluates the expression on the right and gives its result to the name on the left. In score = score + 3, Python first reads the old value, adds three, then assigns the new value. It is an update, not a mathematical claim that a number equals itself plus three.
| Type | Example | Suitable use |
|---|---|---|
| Integer | 12 | Number of seats |
Real, represented here by float | 12.5 | Measured distance |
| Boolean | True | Whether a seat is booked |
| String | "012" | A code whose leading zero matters |
| Character | "A" | One symbol; Python uses a string of length one |
Python does not need a separate declaration before assignment. That does not mean types are unimportant: the operation must make sense for the values involved. "12" + "3" concatenates text to produce "123"; 12 + 3 produces the integer 15. Do not choose a numeric type merely because a reference code contains digits.
Use names such as passenger_count, not unexplained single letters. A constant represents a value intended to remain fixed. Python convention uses names such as BOOKING_FEE = 6; capital letters communicate intent but do not prevent reassignment. Explain both the purpose of a constant and this limitation.
Expressions and input
input() returns a string. Conversion makes numeric processing possible: int("12") produces a whole number and float("12.5") produces a real value. Conversion is not validation. int("twelve") fails with a runtime error, and int("-4") succeeds even if negative passenger counts are forbidden.
| Expression | Result | Reason |
|---|---|---|
17 // 5 | 3 | Whole groups of five |
17 % 5 | 2 | Remainder after making those groups |
17 / 5 | 3.4 | Ordinary division |
2 ** 4 | 16 | Exponentiation |
(3 + 4) * 2 | 14 | Parentheses change the calculation |
Multiplication and division are evaluated before addition and subtraction. Parentheses make an intended calculation explicit. For non-negative quantities, integer division and remainder are especially useful for converting units or packing items. Do not use / when the output must count complete groups.
Sequence matters. A name must be assigned before its value is used. Output does not change the value unless another assignment explicitly does so. A comment begins with # and explains the code to a reader; Python does not execute the comment.
Worked example: booking a minibus
BOOKING_FEE = 6
PRICE_PER_PASSENGER = 4
passengers = int(input("Passengers: "))
total = BOOKING_FEE + passengers * PRICE_PER_PASSENGER
print("Total:", total)
For input 3, conversion gives the integer 3. Multiplication gives 12, then the booking fee produces 18. The final line displays Total: 18. It does not store the text "Total:" in total. Trace another input before running the code.
| Input | Expected output | What it checks |
|---|---|---|
| 0 | Total: 6 | Fixed fee is charged even with no passengers, under this rule |
| 1 | Total: 10 | One unit of the variable charge |
| 8 | Total: 38 | A typical larger booking |
These tests check the stated calculation, not a realistic booking policy. If the requirements later say one to eight passengers only, validation must be added. Never silently invent a restriction: state the assumptions, then test the specified behaviour.
Worked example: complete boxes and leftovers
A warehouse packs 47 pens into boxes holding six pens. The complete boxes are 47 // 6 = 7; the remainder is 47 % 6 = 5. Seven full boxes account for 42 pens, and five remain. This gives a useful check: boxes * capacity + remainder must equal the original quantity.
pens = 47
capacity = 6
boxes = pens // capacity
remaining = pens % capacity
print("Full boxes:", boxes)
print("Pens left:", remaining)
Do not confuse full boxes with boxes required to hold everything. The latter would need an extra box when a remainder exists. That decision belongs to the selection chapter. Try quantities 0, 6, 7 and 12 and describe why exact multiples are useful tests.
Independent practice
Original Proof Academy task · 8 marks. A bike hire costs a fixed £3 plus £5 per complete hour. Assume the input is a non-negative whole number of hours. Write a program that reads the hours, calculates the charge and displays a labelled result. Use named constants. Then record expected results for 0, 1 and 4 hours before running it.
Repair this statement and explain the error: minutes = input("Minutes: "); hours = minutes // 60. Your explanation must identify the type returned by input and the conversion needed. Do not merely say “it does not work”.
Worked feedback and 8-mark scheme
Award one mark each for: reading input; converting to integer; a named fixed-fee constant; a named hourly-rate constant; multiplying hours by the rate; adding the fee; a labelled output; all three correct expected results. Outputs are 3, 8 and 23. Equivalent readable code earns credit.
FIXED_FEE = 3
HOURLY_RATE = 5
hours = int(input("Hours: "))
charge = FIXED_FEE + hours * HOURLY_RATE
print("Charge:", charge)
For the repair, use minutes = int(input("Minutes: ")) before hours = minutes // 60. A string cannot be divided by an integer using //. This conversion assumes a valid whole-number entry; it does not reject negative values.
Homework and readiness check
Allow 30 minutes. Read a non-negative whole-number duration in seconds. Display complete minutes and leftover seconds. Test 0, 59, 60, 61 and 125. Explain why division alone does not produce the required pair of outputs.
Check your homework
Use minutes = seconds // 60 and remainder = seconds % 60. The pairs are (0,0), (0,59), (1,0), (1,1) and (2,5). Check that minutes * 60 + remainder == seconds for every test. A readiness explanation distinguishes a string from an integer, assignment from comparison, and ordinary division from complete-group counting.
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.
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.