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

Preview

Build the solution in small steps

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

45 minutes

Two ways to build a wall

Builder A puts down all the bricks for the whole house and then checks. A wall that is not straight is found on the last day.

Builder B puts down one row of bricks and checks it. Then the next row, and checks again. A wall that is not straight is found in a minute.

Be Builder B. In the build task, a small working step is always better than a big broken one.

Key words

WordWhat it meansExample
BuildWrite the code that makes the solution.write book()
PrototypeAn early working version that does the main job.it books a court
CommentA note in the code for people. Python ignores it.# check the hour first
Naming conventionA rule for how you write names, so they are easy to read.price_for, not pf
VersionA saved copy of your work at one moment.booking_v2.py
Version controlA tool that keeps every saved version of your work.Git
Must-haveA part the tool needs. It must be in the tool.book a court
Should-haveAn important part, but the tool still works without it.cancel a booking
ModuleA part of the program that does one job and can be tested alone.the pricing part

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

Step 1: try a booking

Code: python
bookings = []


def book(bookings, member, court, hour):
    bookings.append({"member": member, "court": court, "hour": hour})
    return True


print(book(bookings, "Sam", 1, 10))
print(bookings)

# This works but it books anything.
# Book Sam on court 1 at hour 10 again. What happens?

Step 2: add one check

Code: python
bookings = []


def is_free(bookings, court, hour):
    for one in bookings:
        if one["court"] == court and one["hour"] == hour:
            return False
    return True


def book(bookings, member, court, hour):
    if not is_free(bookings, court, hour):
        return False
    bookings.append({"member": member, "court": court, "hour": hour})
    return True


print(book(bookings, "Sam", 1, 10))
print(book(bookings, "Aisha", 1, 10))
print(len(bookings))

One check at a time

data-callouts.tip.label

Step 1 booked anything. Step 2 added one check. The next step adds the hour check. The next adds the court check. After every step the code runs. That is how you stay sure the code works.

Quick check: building well

Have a go

Quick check: building well

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

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

The lesson goes on

3 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.