Students meet a variable that changes itself, size = size + 5, and use it to grow a spiral without the loop counter.
Core ideas this lesson introduces: Changing a variable (a hinge idea) needs Variables. How the ideas build
Open these in Waypoints Prepare with one click. To share a file another way, copy its address and paste it into Load URL, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
Predict and Run 10 min · Investigate 12 min · Modify 5 min · Make 8 min
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.
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.
Think aloud: size starts at 10, so I write 10 in my table. Go round once: forward 10, then size becomes 15. Round again: forward 15, size becomes 20. I stop when I get to the line where my table disagrees with the picture. That's where I look.
Here is the finished program running. By the end of the lesson you will write one like it.
Run the finished example on the projector before anything else.
The class calls out size after each pass while one student updates a number on the board.
Make the idea physical before it goes back to the screen.
Reading size = size + 5 as an equation. Have them trace the first three values on paper before running it.
| What you will see | A question to ask | The 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. |
One possible solution for each task. Other correct programs are fine.
from turtle import *
size = 0
for i in range(30):
forward(size)
right(90)
size = size + 10
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: 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.
What does size = size + 5 do if size is 20?
It works out 20 + 5 = 25 and stores 25 back in size.
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.