All subjects · Computer Science · WCP02 Practical Programming and Problem-solving
Computational thinking in code: abstraction, decomposition, patterns and generalisation
Edexcel IAL Computer Science · WCP02 Practical Programming and Problem-solving
The four parts of computational thinking each show up in the code you write. The specification ties each one to a programming habit.
Abstraction (spec 10.1.1)
Abstraction hides detail that is not needed. In code, a subprogram hides its implementation: whoever calls is_prime(n) needs to know what it returns, not how it works. The stack lesson's push() and pop() are abstractions: the main program never touches top directly.
Decomposition (spec 10.1.2)
Break the problem into parts and describe the algorithm in a first comment before coding, then turn each part into code or a subprogram:
# Read sensor readings from the file
# Find the first invalid reading for each sensor
# Display the faulty sensors in a table and write them to a filePattern recognition and generalisation (spec 10.1.3, 10.1.4)
Pattern recognition: spot that a new problem is like one you have solved and reuse the same solution, subprogram or data structure (a running total, a linear search, a 2D list of records).
Generalisation: write one solution for a family of problems by turning fixed values into parameters.
def count_in_range(values, low, high):
count = 0
for v in values:
if low <= v <= high:
count = count + 1
return count
marks = [35, 72, 58, 90, 41]
print(count_in_range(marks, 70, 100))
print(count_in_range(marks, 40, 59))
ages = [12, 17, 15, 19]
print(count_in_range(ages, 13, 19))Output:
2
2
3Worked example
A program has three loops: one counts marks of 70 or more, one counts marks from 50 to 69, one counts marks below 50. Generalise them.
- Recognise the pattern: each loop counts values between two limits.
- Write one function count_in_range(values, low, high).
- Call it three times: (70, 100), (50, 69), (0, 49).
Answer: One general function with the limits as parameters replaces three loops
Check yourself
- Which is the best example of abstraction in a program?
- Writing every step of the program in the main block
- Calling is_valid(mark) without needing to know how it checks the mark
- Using a for loop instead of a while loop
- Printing the value of every variable
Show answer
Calling is_valid(mark) without needing to know how it checks the mark. The subprogram hides its implementation behind a name and an interface.
- A function draws a 5 by 5 grid of stars. How would you generalise it?
- Copy it and change 5 to 6 in the copy
- Add a comment saying it draws a grid
- Make the grid size a global variable that other code changes
- Add parameters for the number of rows and columns
Show answer
Add parameters for the number of rows and columns. Generalisation turns the fixed values into parameters so one function solves the whole family of problems.
- According to the specification, how can you show decomposition in your code?
- Write the whole program on one line
- Begin with a first comment that describes the steps of the algorithm
- Use only global variables
- Avoid subprograms
Show answer
Begin with a first comment that describes the steps of the algorithm. A first comment outlining the parts is the decomposition, and each part then becomes code.
- You have written a linear search for names in a list. A new task needs to find a product code in a list of codes. What does pattern recognition suggest?
- Write a completely new algorithm
- Sort the list three times first
- Reuse the same linear search approach or subprogram
- Store the codes in a text file instead
Show answer
Reuse the same linear search approach or subprogram. The problem has the same shape, so the same solution applies.
- What is displayed when this code runs?
```python
def count_in_range(values, low, high):
count = 0
for v in values:
if low <= v <= high:
count = count + 1
return count
print(count_in_range([4, 9, 15, 21, 30], 10, 25))
```
Show answer
2. Values from 10 to 25 inclusive are 15 and 21: 2.
- What is displayed when this code runs?
```python
def repeat_char(ch, n):
line = ""
for i in range(n):
line = line + ch
return line
print(repeat_char("#", 3) + repeat_char("-", 2))
```
Show answer
###--. The general function builds ### and --, joined: ###--.
Sources
- Pearson Edexcel International Advanced Subsidiary/Advanced Level in Computer Science specification (XCP01/YCP01), first teaching 2026
- Pearson IAL Computer Science Unit 2 Programming Language Subset (PLS), Python 3
- Pearson IAL Computer Science IAS sample assessment materials (Unit 2 paper and mark scheme)
Last updated 8 November 2026. Spotted a mistake? Tell us.