← Teacher guide

A street of houses

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.

Python Foundations with Turtle · Commands, loops and values · about 45 minutes · Open the student lesson

Classroom resources

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.

Students will be able to

Timing

Watch 5 min · Predict and Run 5 min · Investigate 15 min · Modify 10 min · Make 10 min

Before class

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.

Running the lesson

  1. Watch: play the clip once, whole class. Pause after each caption and ask what the next lines will do before they appear. The captions are the program's parts: name the numbers, move to the start, one house (walls, roof, step along), work out the length.
  2. Predict: students commit to the printed length for 5 houses before running. The common wrong answer is 400 (5 gaps instead of 4): ask them to count the gaps on the 4-house picture.
  3. Investigate: this is the heart of the lesson. The match and trace tasks are about parts and how they connect, not single lines. Ask: which lines would you change to make the roofs taller? (None alone: the roof is drawn with width, so it follows the walls.)
  4. Modify: use the live slide to change one number together (houses to 6 shows the length growing), then students work on their own screens. They change one thing and run. The third task is a real question: after the houses grow, the printed length is wrong, because the formula assumes every house is the same width.
  5. Make: students work alone here; walk round, or use the live slide to build one part with the whole class. The new part needs its own loop and variable. Early finishers can make it depend on an existing variable (a fence as long as the street).

In class

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.

The hard part (on purpose)

Reading a program longer than one screen. Ask students to say the job of each part aloud before they look at any single line.

When students get stuck

What you will seeA question to askThe 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.

Answers to the checks

  1. Predict: Change houses to 5. What number will the last line print?
    380. Five houses of 60 make 300, and the four gaps between them make 80 more: 5 × 60 + 4 × 20 = 380.
  2. Find the parts: Match each part of the program with its job.
    for side in range(4): → B. draws the walls; left(90) then forward(width), right(30) ... → C. draws the roof and comes back down to the ground; penup(), forward(gap), pendown() → D. moves to where the next house starts, without drawing; for house in range(houses): → A. repeats everything indented under it, once per house
    The outer loop repeats a whole house: walls, roof and the move along. The inner loop repeats only the walls.
  3. Follow a change: Back to 4 houses. Change width to 70 and leave the rest. What will the last line print?
    340
    4 × 70 + 3 × 20 = 340. Every part that uses width follows the change: the walls, the roof and the length.
  4. Spot the bug: With houses = 4 this street looks right. Change houses to 6 and the roofs go wild. Click the wrong line.
    line 14
    The walls loop repeats houses times instead of 4. It only looked right because houses happened to be 4. A square always has 4 sides, whatever houses is.

Solutions

One possible solution for each task. Other correct programs are fine.

Modify › Six houses

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)

Modify › Growing houses

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

Modify › Is the length still right?

Open task: any program that does what the step asks.

Make › Add a part

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)

Make › Make it adjustable

Open task: any program that does what the step asks.

Lay a tiled floor

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 and support

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.

Exit ticket

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).

What each step is for

Where it leads

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.