Same idea, three forms
You can show a friend the way to the station in three ways. You can draw a map. You can say the steps. You can use a phone app.
An algorithm is the same. We can draw it as a flowchart. A flowchart is a picture made of shapes and arrows. We can write the steps in words. Or we can write code.
Key words
| Word | What it means | Example |
|---|---|---|
| Written description | An algorithm written as numbered steps in plain words. | 1 Ask for the age |
| Hierarchical marker | A number that shows the order and what belongs to what. | 1, 2, 2.1, 2.2, 3 |
| Code | Instructions in a programming language that a computer runs. | print("Hi") |
| Translate | Say the same algorithm in another way. | from a flowchart to code |
| Flowchart | A picture of an algorithm made of shapes and arrows. | start, check age, end |
| Selection | Choosing a path by asking a question. | if age is under 16 |
| Iteration | Repeating steps. | while n is more than 0 |
| Loop | Another name for iteration. | repeat while n is more than 0 |
The cells students fill in are left blank in this preview.
A bus fare in words
| Marker | Step |
|---|---|
| 1 | Ask for the age. |
| 2 | If the age is under 16: |
| 2.1 | The fare is 1. |
| 3 | Otherwise: |
| 3.1 | The fare is 2. |
| 4 | Show the fare. |
The cells students fill in are left blank in this preview.
Read the steps
Have a go
Read the steps
3 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.
Written steps with markers
A written description uses numbers. The numbers show the order. A step with a number like 2.1 belongs to step 2.
This is the hierarchical marker idea: the bigger numbers are the main steps. The numbers with a dot are the smaller steps inside.
The same algorithm as Python code
age = 12
if age < 16:
fare = 1
else:
fare = 2
print(fare)
# Change age to 30 and run it again.
More than two choices
data-callouts.tip.label
Use elif for a second question. It means "else if". Python checks if, then each elif, then else. It runs only the first one that is true.
Translate step by step
| Flowchart | Written steps | Python |
|---|---|---|
| Input: age | 1 Ask for the age | age = int(input("Age? ")) |
| Decision: age under 16? | 2 If the age is under 16 | if age < 16: |
| Process: fare is 1 | 2.1 The fare is 1 | fare = 1 |
| Other arrow (no) | 3 Otherwise | else: |
| Output: fare | 4 Show the fare | print(fare) |
The cells students fill in are left blank in this preview.