Students give numbers names (variables) and let the program calculate the turn, so one change at the top updates the whole shape.
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.
Predict and Run 10 min · Investigate 12 min · Modify 6 min · Make 8 min · Room plan 4 min
Run the first program, then make the shape generator from the Make step. Notice how little you change to get a different shape: that is the point of the lesson.
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.
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.
Students hold cards for sides, size and colour. Change one card; the class says which drawing changes.
Make the idea physical before it goes back to the screen.
Swap screens with the next pair. Change one number in their generator and say what shape it will draw before you run it.
Seeing that a name holds a value the program can reuse. Ask them to say, for each line, which stored value it uses.
| What you will see | A question to ask | The fix |
|---|---|---|
| The shape does not close, or the turtle spins in place. | What is stored in angle when sides is 5? Work it out on paper. | angle must be 360 / sides (divide, not multiply). |
| A NameError says a name is not defined. | Is the name spelt exactly the same everywhere, including capitals? | Variable names must match exactly. Size and size are different names. |
| A student changes a variable after the loop and expects the shape to change. | Which lines already ran before you changed it? | Lines use the value a name holds when they run. Put the change above the loop. |
One possible solution for each task. Other correct programs are fine.
from turtle import *
sides = 12
size = 40
angle = 360 / sides
for i in range(sides):
forward(size)
right(angle)
from turtle import *
sides = 6
size = 80
angle = 360 / sides
colour = "purple"
pencolor(colour)
for i in range(sides):
forward(size)
right(angle)
from turtle import *
scale = 20 # pixels per metre
width = 8 # metres
depth = 5
for i in range(2):
forward(width * scale)
right(90)
forward(depth * scale)
right(90)
# A second room beside the first: 4 m by 5 m.
forward(width * scale)
for i in range(2):
forward(4 * scale)
right(90)
forward(depth * scale)
right(90)
Stretch: Change sides to 3, 4, 5 and up to 20, and record which values still look like the shape and which look like a circle.
Support: Give students a table with two columns (sides, angle) and ask them to fill in angle for 3, 4, 5 and 6 before running anything.
A program has sides = 8 and angle = 360 / sides. How far does the turtle turn at each corner?
45 degrees (360 divided by 8).
Next lesson uses the loop counter, so a value can change each pass without being typed. After that, a value that grows. Scores, game settings and the scale on maps and plans all use variables. Class ideas: a spiral gallery; scale drawings of the classroom.