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
| Word | What it means |
|---|---|
| Flowchart | A diagram that shows the steps of a program as symbols joined by arrows. |
| BCS symbols | The standard flowchart shapes used in the UK. BCS is the Chartered Institute for IT. |
| Pseudocode | Planning a program in plain words that look like code. No computer runs it. |
| Sequence | Steps that happen one after another. |
| Selection | A choice between two paths. Also called branching. |
| Loop | Steps that repeat. |
| Iteration | Doing steps again and again. Also called a loop. |
| Control structure | Sequence, selection or iteration. They control the order of the steps. |
| Pre-defined code | Code that already exists and that you reuse. |
The cells students fill in are left blank in this preview.
Flowchart symbols
| Symbol | Shape | Use it for | Example |
|---|---|---|---|
| Terminator | Rounded box | Start and end | Start |
| Process | Rectangle | A step that does something | Add 1 to total |
| Decision | Diamond | A yes or no question. Two exits. | Is age under 16? |
| Input or output | Parallelogram | Data in or out | Enter your age |
| Pre-defined process | Rectangle with double side lines | Code that already exists | Check the age is a number |
| Flow line | Arrow | Shows the order | From 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
| Structure | In a flowchart | In pseudocode |
|---|---|---|
| Sequence | Steps in a line | SET price TO 5, then SET total TO price + 1 |
| Selection | A diamond with two exits | IF age < 16 THEN OUTPUT "child" ELSE OUTPUT "adult" END IF |
| Iteration | An arrow that goes back up | FOR 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
# 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 questionsDraw 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.
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