Students watch a 30-line program being built part by part, then read it closely, change it and add to it. It uses only loops, variables and calculations from lessons 1 and 2; the new skill is reading a whole program.
Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
Watch 5 min · Predict and Run 5 min · Investigate 15 min · Modify 10 min · Make 10 min
Watch the build clip, then try the bug task with houses = 6. The bug (a loop that repeats houses times instead of 4) hides while houses is 4; that is the point of the lesson: parts of a program depend on each other in ways you only see when something changes.
On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.
Expect both views. Reading is how you find where to make a change safely, so readable code saves time overall; but unclear code is a sign something is wrong. Come back to this at the jigsaw: which parts of the street program made it easy or hard to read?
Today's program is 30 lines long. It uses only loops and variables, which you already know. The skill today is reading: which part does which job?
Play the Watch it built clip on the projector, pausing after each caption: what will the next lines do?
Half the pairs read the walls and the roof. The other half read the move along and the last line. You have 3 minutes. Then find a pair from the other half and explain your part, line by line.
This is Code.org's jigsaw from its Investigate lessons. Finish with the class naming the plan: repeat a unit, then step along. Ask where else they would use it (a fence, a row of tiles, a bar chart).
Repeat a unit, then step along: draw one thing, move to where the next one starts, loop. Work it out from the variables: the last line calculates the length from houses, width and gap. Where else could you use each one?
Driver types, navigator checks the printed length after every change. Swap after each task.
Leave your street on screen. Walk round and find one street that does something yours doesn't. Back at your desk: in one sentence, what does your program do?
The one-sentence summary is the standard test of reading a whole program (explain in plain English). Collect a few aloud.
Reading a program longer than one screen. Ask students to say the job of each part aloud before they look at any single line.
| What you will see | A question to ask | The fix |
|---|---|---|
| The houses are drawn on top of each other, or only one house appears. | Which lines move the turtle along, and are they indented under the house loop? | penup, forward(gap) and pendown must be inside the house loop, so the turtle steps along after every house. |
| The roofs point sideways or downwards after changing houses. | How many times does the walls loop repeat? Should that depend on how many houses there are? | A square always has 4 sides, so the walls loop is range(4), not range(houses). |
| A student's new part starts in the wrong place. | Where is the turtle, and which way is it facing, when the house loop ends? | It is at the ground after the last gap, facing right. Start the new part from there, or move with penup first. |
One possible solution for each task. Other correct programs are fine.
from turtle import *
speed(0)
houses = 6
width = 50
gap = 20
penup()
backward(220)
pendown()
for house in range(houses):
# walls
for side in range(4):
forward(width)
left(90)
# roof
left(90)
forward(width)
right(30)
forward(width)
right(120)
forward(width)
right(30)
forward(width)
left(90)
# move along to the next house
penup()
forward(gap)
pendown()
print(houses * width + (houses - 1) * gap)
from turtle import *
speed(0)
houses = 4
width = 40
gap = 20
penup()
backward(220)
pendown()
for house in range(houses):
# walls
for side in range(4):
forward(width)
left(90)
# roof
left(90)
forward(width)
right(30)
forward(width)
right(120)
forward(width)
right(30)
forward(width)
left(90)
# move along to the next house
penup()
forward(gap)
pendown()
width = width + 10
Open task: any program that does what the step asks.
from turtle import *
speed(0)
houses = 4
width = 60
gap = 20
posts = 8
penup()
backward(220)
pendown()
for house in range(houses):
# walls
for side in range(4):
forward(width)
left(90)
# roof
left(90)
forward(width)
right(30)
forward(width)
right(120)
forward(width)
right(30)
forward(width)
left(90)
# move along to the next house
penup()
forward(gap)
pendown()
# a fence: one post, then step along, posts times
for post in range(posts):
left(90)
forward(30)
backward(30)
right(90)
forward(10)
Open task: any program that does what the step asks.
from turtle import *
# Two rows of six bigger tiles.
for row in range(2):
for tile in range(6):
for side in range(4):
forward(50)
right(90)
penup()
forward(50)
pendown()
penup()
backward(300)
right(90)
forward(50)
left(90)
pendown()
Stretch: Make the fence exactly as long as the street, using the same calculation as the last line.
Support: Give the match task first on paper, cutting the program into its parts, before students touch the code.
The street has houses = 3, width = 50 and gap = 10. What does the last line print, and where does house 2 start if house 1 starts at x = -220?
170 (3 × 50 + 2 × 10). House 2 starts at -160 (-220 + 50 + 10).
This is the shape of every later unit: a few short lessons on new ideas, then a longer program that puts them together. Next unit adds decisions (if) and lists, and its programs grow the same way.