Define the problem before the program
A sports centre wants to calculate entry charges. “Make an entry program” is too vague to implement reliably. A useful specification states the input, valid values, processing rules and exact output. For example: input is a whole-number age; valid ages are 0–120; under-16s pay £4 and everyone else pays £7; an invalid age produces Invalid age without a price.
An algorithm is a finite set of ordered, unambiguous steps for solving a problem. A program implements those steps in a language a computer can execute. The same algorithm can be expressed as a flowchart, informal pseudocode or Python. Edexcel's specification treats pseudocode as an informal description rather than one compulsory syntax: your steps still need to be clear and complete.
Use this chapter to move through specification, decomposition, abstraction, algorithm design, trace and testing. Spend the first ten minutes rewriting the sports-centre brief as four headings: input, constraints, processing and output. Do not start coding until another person could predict the intended result for ages 15 and 16.
Decomposition and abstraction
Decomposition divides a problem into smaller tasks. For the entry system, separate reading the age, checking its range, choosing the price and displaying the result. Each task has a purpose that can be reasoned about independently. When implemented as suitable subprograms, these tasks become easier to test and reuse. Merely putting blank lines in a program is not decomposition.
Abstraction retains relevant information and leaves out details that do not affect the model. The charge calculation needs age, not shoe size or the colour of the reception desk. Whether a name is relevant depends on the requirements: it is unnecessary for this calculation but could matter for printing a named booking confirmation.
A model can become wrong if abstraction removes something essential. If members receive a discount, membership status is relevant. Ask “could this detail change the required output?” rather than assuming that simpler always means better. A strong answer identifies the retained or omitted detail and explains why that decision supports this particular task.
Representing the same decision
In a flowchart, a terminator marks start or stop, a parallelogram indicates input or output, a rectangle represents processing and a diamond represents a decision. Arrows show the direction of execution. Label the exits from a decision so the reader can follow both outcomes. A loop needs an arrow returning to an earlier step and a reachable exit.
The entry algorithm can be written as follows:
INPUT age
IF age is below 0 OR above 120
OUTPUT "Invalid age"
ELSE
IF age is below 16
SET price TO 4
ELSE
SET price TO 7
END IF
OUTPUT price
END IF
For age 16, the invalid-range condition is false, the under-16 condition is false and the price is seven. Notice that outputting the price belongs only inside the valid branch. Placing it after the entire algorithm could attempt to use a price that was never assigned for invalid input.
Convert the pseudocode into a flowchart on paper. Then use Python indentation to express the same blocks. Your representation may look different, but every valid and invalid input must still follow an equivalent path.
Trace the state, not your expectation
A trace table records changing values as instructions execute. It is not a summary of what you think the program ought to do. Give each changing variable a column, identify the loop iteration or executed line and include output when relevant. Leave a value unchanged when the instruction does not modify it.
total = 0
count = 0
for value in [3, 5, 2]:
total = total + value
count = count + 1
print(total, count)
| Stage | value | total | count | Output |
|---|---|---|---|---|
| Initialisation | — | 0 | 0 | — |
| First body completed | 3 | 3 | 1 | — |
| Second body completed | 5 | 8 | 2 | — |
| Third body completed | 2 | 10 | 3 | — |
| Final output | 2 | 10 | 3 | 10 3 |
The table records the state after each complete loop body. A question asking for values after every assignment needs finer-grained rows. State the convention and follow the question. The initial row matters because it establishes what the first addition and increment use.
Locate an error with evidence
A syntax error breaks the language's rules, such as a missing colon after if. A runtime error occurs during execution, such as converting "cat" with int() or dividing by zero. A logic error lets the program execute but gives behaviour inconsistent with the requirements.
Suppose the loop above contains total = value instead of total = total + value. It finishes with total 2 because each assignment replaces the previous total. Python accepts the instruction: the defect is logical. The earliest divergence appears in the second row, where the total becomes 5 instead of 8. Identifying that first wrong state is usually more useful than staring at the final output.
Use a disciplined repair cycle: predict, run, compare, locate, change, rerun. Change one relevant cause rather than several unrelated lines. Rerun earlier successful cases as well as the failing case so a repair does not create a new defect.
Independent practice
Original Proof Academy task · 8 marks. A program should count how many numbers in [2, 8, 5, 9] are at least five. Write an algorithm, trace it and state the result. Explain what would happen if the counter were initialised inside the loop rather than before it.
Worked feedback and 8-mark scheme
Award: initialise counter before the loop [1]; traverse every item [1]; use >= 5 [1]; increment only on a match [1]; trace counters 0, 1, 2, 3 after the four values [2]; final result 3 [1]; explain that resetting inside the loop loses earlier matches [1].
count = 0
for value in [2, 8, 5, 9]:
if value >= 5:
count = count + 1
print(count)
This tests the threshold itself, not just values above it. Replacing >= with > incorrectly excludes 5 and produces 2. Testing only 8 and 9 would miss that defect.
Exam practice and homework
Original practice · 4 marks. A library reminder system needs a borrower's identifier, due date and return date. Explain one use of decomposition and one use of abstraction. Give a specific example for each rather than repeating the definitions.
Four-mark feedback
Decomposition: separate calculating lateness from creating the reminder [1], allowing the lateness calculation to be tested without sending messages [1]. Abstraction: omit the borrower's favourite colour [1] because it does not affect whether the loan is overdue [1]. Other relevant examples are valid.
For homework, design a flowchart that reads three non-negative scores and outputs their total. Trace 0, 5, 10 and a second set containing all zeros. Then modify the design to count scores of at least ten. Label each decision exit and show where the total and counter are initialised. You are ready to continue when you can explain why initialisation belongs before repeated work and can distinguish the intended rule from the code's actual behaviour.
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.