Students use the loop counter i to work out something different on every pass, and meet the fact that counting starts at 0.
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 8 min · Modify 12 min
Run the spiral, then try pensize(i + 1) yourself. Notice the first line is invisible because i is 0.
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.
Four volunteers say i aloud as the loop runs, 0, 1, 2, 3, while the class says each line length.
Make the idea physical before it goes back to the screen.
Believing the counter is the same number every pass, or that it starts at 1. Ask what i is on the first pass.
| What you will see | A question to ask | The fix |
|---|---|---|
| The spiral is a square, with every line the same length. | Is the length worked out from i, or typed as a number? | The length must use i, for example forward(i * 5). |
| A student expects the first line to be 5 long. | What is i on the very first pass? | i is 0 on the first pass, so i * 5 is 0. Counting starts at 0. |
| An error says i is not defined. | Is the line that uses i indented inside the for loop? | i only exists inside the loop. Indent the line under the for line. |
One possible solution for each task. Other correct programs are fine.
from turtle import *
for i in range(30):
forward(i * 10)
right(90)
from turtle import *
for i in range(30):
pensize(i + 1)
forward(i * 5)
right(90)
Stretch: Draw a spiral that turns 91 degrees instead of 90. What happens, and why?
Support: Give the first three values of i * 5 and ask the student to continue the pattern before running.
In for i in range(5): forward(i * 10), what is the length of the third line?
20. The third pass has i = 2, and 2 * 10 = 20.
Next lesson makes a value grow without the counter: a variable that adds to itself. Counters are used for scores, timers and animations. Class ideas: a spiral gallery with different multipliers.