← Teacher guide

A value that grows

Students meet a variable that changes itself, size = size + 5, and use it to grow a spiral without the loop counter.

Python Foundations with Turtle · Commands, loops and values · about 35 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

Predict and Run 10 min · Investigate 12 min · Modify 5 min · Make 8 min

Before class

Run the spiral, then make the thickening spiral from the Make step. The key line is size = size + 5, which looks wrong to anyone used to maths: in Python it means "work out size + 5, then store it back in size". Be ready to say that out loud.

Running the lesson

  1. Predict: show the spiral and ask whether it looks different from last lesson's. The wrong options include an error, because many students think size cannot equal size + 5. The counter spiral and the update spiral look the same: ask why before running.
  2. Say it aloud: read size = size + 5 right to left. Work out size + 5, then store the answer back in size. Say 'store' instead of 'equals'.
  3. Investigate: settle what is stored, trace the value over four passes, then show the update outside the loop and ask what happens. The last question links back to the counter: two ways to get the same lengths.
  4. Modify: one number changes. Let students predict before they run.
  5. Make: a second variable that updates itself. Students who finish can try changing the amount added to the thickness.

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 size = size + 5 as an equation. Have them trace the first three values on paper before running it.

When students get stuck

What you will seeA question to askThe fix
The spiral is a square, with every line the same length.Does anything change size while the loop runs?Add size = size + 5 as the last line inside the loop (indented).
One small square is drawn over and over.Is the update line indented under the for line?The update must be inside the loop to run on every pass.
A student thinks size = size + 5 is an error.Which side does Python work out first?Work out the right side, then store the answer in the name on the left.

Answers to the checks

  1. Predict: Last lesson the spiral used the counter. This one uses size = size + 5. What will it draw?
    The same spiral. size starts at 0 and grows by 5 on every pass: 0, 5, 10, 15. That is exactly what i * 5 gave last lesson.
  2. Store it back: A program has size = 20. Then it runs the line size = size + 5. What is stored in size afterwards?
    25
    Read the line from the right. Python works out size + 5, which is 25, then stores 25 back in size. The = means store, not 'is equal to'.
  3. Watch it grow: Fill in the size that forward(size) uses on each pass.
    20, 30, 40
    The last line of each pass stores size + 10 back in size, so the next pass starts with a bigger size. This is how a spiral grows.
  4. Spot the bug: This should draw a growing spiral, but it draws one small square over and over. Click the wrong line.
    line 8
    size = size + 5 is not indented, so it runs once, after the loop. Inside the loop it runs on every pass. Indent it under the for line.
  5. Same lengths, two ways: Last lesson's lines were i * 5. This lesson's size starts at 0. Which update inside the loop gives the same lengths?
    size = size + 5
    Adding 5 each pass gives 0, 5, 10, 15, the same as i * 5. size * 5 stays at 0, size = i gives 0, 1, 2, and size = 5 is always 5.

Solutions

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

Modify

from turtle import *

size = 0

for i in range(30):
    forward(size)
    right(90)
    size = size + 10

Make

from turtle import *

size = 0
width = 1

for i in range(30):
    pensize(width)
    forward(size)
    right(90)
    size = size + 5
    width = width + 0.5

Stretch and support

Stretch: Make the spiral shrink instead, by subtracting each pass. What happens when size goes below 0?

Support: Give the trace table with the first two rows filled in and ask the student to continue it.

Exit ticket

What does size = size + 5 do if size is 20?

It works out 20 + 5 = 25 and stores 25 back in size.

What each step is for

Where it leads

Next, a street of houses reads a whole program that uses loops, names, the counter and updates together. Scores, timers and bank balances all update this way. Class ideas: a growing-colour spiral; a countdown.