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.

Practise this in the app: instant marking and a fix for every mistake. Free, no email needed to start.

Practise this lesson

Matching symbols to code (spec 10.2.1)

Flowchart symbolMeaningPython
Rounded box (terminal)Start or stopstart or end of the program or subprogram
ParallelogramInput or outputinput(), print(), file read or write
RectangleProcessassignment or calculation
DiamondDecision (yes or no)if / elif / else, or the condition of a while loop
Arrow looping backRepetitionwhile loop (or for loop if the count is fixed)
Rectangle with double sidesSubprograma 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.'

  1. Fixed number of repeats: for i in range(5):
  2. Initialise highest before the loop: highest = None, or the first value
  3. Decision inside the loop: if highest is None or temp > highest: highest = temp
  4. Output after the loop: print(highest)

Answer: for loop, if inside it, print after it

Key idea: Parallelogram: input/output; rectangle: process; diamond: if or loop condition; a back arrow: a loop. Initialise before loops, output after them, and do not process a rogue value.

Check yourself

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

Practise with instant feedback

Sources

Last updated 8 November 2026. Spotted a mistake? Tell us.