All subjects · Computer Science · WCP02 Practical Programming and Problem-solving
Turning algorithms in words and flowcharts into Python
Edexcel IAL Computer Science · WCP02 Practical Programming and Problem-solving
Exam questions describe algorithms in words, diagrams or flowcharts. You must translate each part into the matching Python construct.
Matching symbols to code (spec 10.2.1)
| Flowchart symbol | Meaning | Python |
|---|---|---|
| Rounded box (terminal) | Start or stop | start or end of the program or subprogram |
| Parallelogram | Input or output | input(), print(), file read or write |
| Rectangle | Process | assignment or calculation |
| Diamond | Decision (yes or no) | if / elif / else, or the condition of a while loop |
| Arrow looping back | Repetition | while loop (or for loop if the count is fixed) |
| Rectangle with double sides | Subprogram | a call to a function or procedure |
Spotting loops in a flowchart
If an arrow goes back to a decision above the steps, the test is made first: a while loop. If the steps come first and the decision afterwards loops back, the body runs at least once: in Python, set up the condition so the loop is entered the first time (for example with a flag or by doing the first input before the loop).
Worked translation
Algorithm in words: 'Set count to 0. Input a number. While the number is not -1: if it is even, add 1 to count; input the next number. Output count.'
count = 0
number = int(input())
while number != -1:
if number % 2 == 0:
count = count + 1
number = int(input())
print(count)With inputs 4, 7, 10, -1 the output is 2. The value -1 is a rogue value (sentinel): it ends the input and is not processed.
Worked example
Translate: 'Repeat 5 times: input a temperature; if it is above the highest so far, store it. Then output the highest.'
- Fixed number of repeats: for i in range(5):
- Initialise highest before the loop: highest = None, or the first value
- Decision inside the loop: if highest is None or temp > highest: highest = temp
- Output after the loop: print(highest)
Answer: for loop, if inside it, print after it
Check yourself
- Which Python construct does a diamond in a flowchart usually become?
- A print statement
- An assignment
- An if statement or a loop condition
- An import statement
Show answer
An if statement or a loop condition. A diamond is a decision with yes and no exits.
- A flowchart box says 'Output total'. Which shape should it be?
- Parallelogram
- Diamond
- Rectangle
- Rounded rectangle
Show answer
Parallelogram. Input and output use a parallelogram.
- The user types 5, 8, 2, 0 and 9. What is displayed?
```python
total = 0
value = int(input())
while value != 0:
total = total + value
value = int(input())
print(total)
```
Show answer
15. The rogue value 0 ends the loop and is not added: 5 + 8 + 2 = 15.
- This code follows the algorithm 'Set n to 6 and result to 1. While n is greater than 0, double result and subtract 2 from n. Output result.' What is displayed?
```python
n = 6
result = 1
while n > 0:
result = result * 2
n = n - 2
print(result)
```
Show answer
8. The loop runs for n = 6, 4, 2: three doublings, giving 8.
- Algorithm: 'For each mark in the list, if the mark is at least 50 add 1 to passes. Output passes.' Which line completes the code?
```python
marks = [45, 50, 72, 38, 66]
passes = 0
for mark in marks:
__________
passes = passes + 1
print(passes)
```
- `if mark > 50:`
- `while mark >= 50:`
- `if marks >= 50:`
- `if mark >= 50:`
Show answer
`if mark >= 50:`. 'At least 50' means >= 50, giving 50, 72 and 66: 3 passes.
- In a flowchart, the steps 'Input password' and 'Add 1 to attempts' come first, then a decision 'Correct?' with the No arrow going back to the input. What does this show?
- A loop that may run zero times
- A loop whose body always runs at least once
- A selection with no loop
- A count-controlled loop of fixed length
Show answer
A loop whose body always runs at least once. The test comes after the body, so the body runs before the first check.
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.