A map app plans first
A map app on your phone does not drive the car. It plans the route first. It knows each turn before you reach it.
A good developer plans the steps first too, before writing code. A plan is easier to change than finished code.
In the design task you draw the steps and say how they work.
Key words
| Word | What it means | Example |
|---|---|---|
| Design | A plan of how something will work, made before you build it. | a flowchart |
| Algorithm | A list of steps that solves a problem. | the steps to check a booking |
| Flowchart | A diagram of steps with arrows. | start, check, book |
| Pseudocode | Steps written in plain words that look like code. | IF hour < 9 THEN refuse |
| Decision | A yes or no question that splits the path in two. | Is the court free? |
| Edge value | A value right at the limit of what is allowed. | hour 9 or hour 20 |
| Symbol | A shape in a flowchart. Each shape has one meaning. | a diamond |
The cells students fill in are left blank in this preview.
The booking check as a flowchart
flowchart TD
start([Start]) --> in[/Input: hour and court/]
in --> d1{Is the hour from 9 to 20?}
d1 -->|no| r1[/Output: Closed/]
d1 -->|yes| d2{Is the court 1 or 2?}
d2 -->|no| r2[/Output: No such court/]
d2 -->|yes| d3{Is it already booked?}
d3 -->|yes| r3[/Output: Taken/]
d3 -->|no| p[Save the booking]
p --> r4[/Output: OK/]
r1 --> stop([End])
r2 --> stop
r3 --> stop
r4 --> stop
Match the symbol to its meaning
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Check: reading the flowchart
Have a go
Check: reading the flowchart
4 questionsPseudocode writes the steps in words
Pseudocode is a plan written in plain words. It looks a bit like code but no computer runs it. Each line matches a part of the flowchart.
Pseudocode has no fixed rules. Keep it short and clear. Write every line in the same way.
Flowchart, pseudocode and Python
| Flowchart | Pseudocode | Python |
|---|---|---|
| Input: hour and court | INPUT hour, court | hour = int(input("Hour: ")) |
| Is the hour from 9 to 20? no | IF hour < 9 OR hour > 20 THEN output Closed | if hour < 9 or hour > 20: |
| Is the court 1 or 2? no | IF court is not 1 or 2 THEN output No such court | if court != 1 and court != 2: |
| Is it already booked? yes | IF (court, hour) is in taken THEN output Taken | if (court, hour) in taken: |
| Output: OK | OUTPUT OK | return "OK" |
The cells students fill in are left blank in this preview.
Try it: the flowchart as code
def check(hour, court, taken):
if hour < 9 or hour > 20:
return "Closed"
if court != 1 and court != 2:
return "No such court"
if (court, hour) in taken:
return "Taken"
return "OK"
taken = [(1, 10)]
print(check(10, 1, taken))
print(check(10, 2, taken))
print(check(8, 1, taken))
# < means less than. > means more than.
# != means is not equal to.
# Try hour 21. Try court 3.
Make a free account to save your work and track your progress.
Stage 3: complete the flowchart
This is stage 3 of the Hillside practice project. Finish the flowchart for working out the price of a booking. Use the right symbol for each step. Every path must reach End. Then test it: write down one member case and one visitor case and follow the arrows.
flowchart TD
start([Start]) --> in[/Input: member and hour/]
in --> d1{Is the hour from 9 to 20?}
d1 -->|no| r1[/Output: Closed/]
%% Add the missing steps below, then an End symbol.
%% 1. If the hour is fine, ask: Is the person a member of the club?
%% 2. Yes: price is 4 an hour. No: price is 6 an hour.
%% 3. Output the price.
Make a free account to save your work, or press Start lab to work through the whole lesson.
Stage 3: turn the chart into code
Turn the flowchart into code. Write check_booking so that it gives back "Closed", "No such court", "Taken" or "OK". The opening hours are 9 to 20 and there are two courts. Press Run Tests to check your work.
def check_booking(hour, court, taken):
# taken is a list of (court, hour) pairs that are already booked.
# Follow the flowchart. Give back one of these messages:
# "Closed" if the hour is before 9 or after 20
# "No such court" if the court is not 1 or 2
# "Taken" if (court, hour) is in taken
# "OK" otherwise
return None
Make a free account to save your work, or press Start lab to work through the whole lesson.
Test the design before you code
Tip
Pick a value. Follow the arrows with your finger. Does it end where you expect? Try a normal value. Try an edge value, such as hour 9 and hour 20. Try a wrong value, such as hour 21. You will find mistakes fast.
Key words crossword
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Final check
Have a go