Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

OS 4.3 (4 of 12): Flowcharts and pseudocode

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

50 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

Instructions anyone can follow

Write down how to make a cup of tea. Give it to a friend. Can they follow it exactly?

"Boil the water." Which pot? "Add milk." How much? Good instructions are clear, in order and complete.

Before you write code, you plan it in this way.

Key words

WordWhat it means
FlowchartA diagram that shows the steps of a program as symbols joined by arrows.
BCS symbolsThe standard flowchart shapes used in the UK. BCS is the Chartered Institute for IT.
PseudocodePlanning a program in plain words that look like code. No computer runs it.
SequenceSteps that happen one after another.
SelectionA choice between two paths. Also called branching.
LoopSteps that repeat.
IterationDoing steps again and again. Also called a loop.
Control structureSequence, selection or iteration. They control the order of the steps.
Pre-defined codeCode that already exists and that you reuse.

The cells students fill in are left blank in this preview.

Flowchart symbols

SymbolShapeUse it forExample
TerminatorRounded boxStart and endStart
ProcessRectangleA step that does somethingAdd 1 to total
DecisionDiamondA yes or no question. Two exits.Is age under 16?
Input or outputParallelogramData in or outEnter your age
Pre-defined processRectangle with double side linesCode that already existsCheck the age is a number
Flow lineArrowShows the orderFrom one step to the next

The cells students fill in are left blank in this preview.

Match each symbol to its job

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

A flowchart: the bus fare

flowchart TD
  start([Start]) --> in[/Input age/]
  in --> check[[Check the age is a number]]
  check --> q{Is age under 16?}
  q -->|yes| child[Fare is 1 pound]
  q -->|no| adult[Fare is 3 pounds]
  child --> out[/Output fare/]
  adult --> out
  out --> stop([End])

Three control structures

StructureIn a flowchartIn pseudocode
SequenceSteps in a lineSET price TO 5, then SET total TO price + 1
SelectionA diamond with two exitsIF age < 16 THEN OUTPUT "child" ELSE OUTPUT "adult" END IF
IterationAn arrow that goes back upFOR i FROM 1 TO 3, OUTPUT i, END FOR

The cells students fill in are left blank in this preview.

All three structures in Python

Code: python
# Sequence
price = 4
count = 3
total = price * count

# Selection
if total > 10:
    print("Big order:", total)
else:
    print("Small order:", total)

# Iteration
for i in range(1, 4):
    print("Ticket", i)

# Pre-defined code: len() and sum() already exist
print(sum([2, 4, 6]) / len([2, 4, 6]))

Make a free account to save your work and track your progress.

Writing pseudocode

Pseudocode looks like code but is for people. No computer runs it.

Use short capital words for the key ideas: INPUT, OUTPUT, SET, IF, THEN, ELSE, END IF, FOR, END FOR, WHILE. Indent (move to the right) the lines inside an IF or a loop. Write one step on each line. The sign < means "is less than".

The exact words can change from place to place. Pick one style and keep to it.

Read the pseudocode

Have a go

Read the pseudocode

4 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Draw a flowchart: guess the number

Draw a flowchart for a number guessing game. The program picks a secret number. The player guesses. If the guess is too high or too low, the program says so and the player guesses again. When the guess is right, the program says "Correct" and ends. Use the right shapes: a terminator, input, a diamond for each question, and arrows. The loop must go back to the guess.

flowchart TD
  start([Start]) --> secret[Pick a secret number]
  secret --> guess[/Input a guess/]
  %% Add the decisions and the loop.

Make a free account to save your work, or press Start lab to work through the whole lesson.

Turn pseudocode into Python

Turn the pseudocode in each comment into Python. Four small functions use sequence, selection, iteration and pre-defined code. Press Run Tests.

Code: python
def rectangle_area(width, height):
    # Pseudocode:
    #   INPUT width, height
    #   SET area TO width * height
    #   OUTPUT area
    return None


def ticket_type(age):
    # Pseudocode:
    #   IF age < 16 THEN OUTPUT "child"
    #   ELSE IF age < 65 THEN OUTPUT "adult"
    #   ELSE OUTPUT "senior"
    return None


def sum_to(n):
    # Pseudocode:
    #   SET total TO 0
    #   FOR i FROM 1 TO n
    #       SET total TO total + i
    #   END FOR
    #   OUTPUT total
    return None


def average(numbers):
    # Use the pre-defined code sum() and len(): do not write a loop.
    return None

Make a free account to save your work, or press Start lab to work through the whole lesson.

Key words crossword

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Exit quiz

Have a go

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.