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
| Word | What it means | Example |
|---|---|---|
| Build | Write the code that makes the solution. | write book() |
| Prototype | An early working version that does the main job. | it books a court |
| Comment | A note in the code for people. Python ignores it. | # check the hour first |
| Naming convention | A rule for how you write names, so they are easy to read. | price_for, not pf |
| Version | A saved copy of your work at one moment. | booking_v2.py |
| Version control | A tool that keeps every saved version of your work. | Git |
| Must-have | A part the tool needs. It must be in the tool. | book a court |
| Should-have | An important part, but the tool still works without it. | cancel a booking |
| Module | A 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
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
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 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.