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

Free lesson

ESP task 3 (1 of 3): Design the steps with a flowchart

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.

45 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

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

WordWhat it meansExample
DesignA plan of how something will work, made before you build it.a flowchart
AlgorithmA list of steps that solves a problem.the steps to check a booking
FlowchartA diagram of steps with arrows.start, check, book
PseudocodeSteps written in plain words that look like code.IF hour < 9 THEN refuse
DecisionA yes or no question that splits the path in two.Is the court free?
Edge valueA value right at the limit of what is allowed.hour 9 or hour 20
SymbolA 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 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

Pseudocode 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

FlowchartPseudocodePython
Input: hour and courtINPUT hour, courthour = int(input("Hour: "))
Is the hour from 9 to 20? noIF hour < 9 OR hour > 20 THEN output Closedif hour < 9 or hour > 20:
Is the court 1 or 2? noIF court is not 1 or 2 THEN output No such courtif court != 1 and court != 2:
Is it already booked? yesIF (court, hour) is in taken THEN output Takenif (court, hour) in taken:
Output: OKOUTPUT OKreturn "OK"

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

Try it: the flowchart as code

Code: python
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.

Code: python
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

Final check

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.