← Teacher guide

Use the counter

Students use the loop counter i to work out something different on every pass, and meet the fact that counting starts at 0.

Python Foundations with Turtle · Commands, loops and values · about 30 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 8 min · Modify 12 min

Before class

Run the spiral, then try pensize(i + 1) yourself. Notice the first line is invisible because i is 0.

Running the lesson

  1. Predict: show the loop with forward(i * 5) and ask what it draws. Take a vote before anyone runs it; the wrong options are a square (the counter does not change), a circle, and an error because i was never stored.
  2. Run: students run it and compare. Ask: how long is the first line, and why?
  3. Investigate: trace the counter 0, 1, 2, 3 and say that counting starts at 0, because later lessons rely on it. The second task checks that a name still holds a value you can calculate with.
  4. Modify: students change the multiplier, then use the counter for the pen. Let them try pensize(i) first: it starts at 0, so the first line is thin. That is a good moment to talk about starting at 0.

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)

Believing the counter is the same number every pass, or that it starts at 1. Ask what i is on the first pass.

When students get stuck

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

Answers to the checks

  1. Predict: What will the turtle draw?
    A spiral. i is 0 on the first pass, 1 on the second, 2 on the third, so i * 5 is 0, 5, 10, and every line is longer than the last.
  2. Follow the counter: Fill in the counter and the length of the line on each pass.
    1, 5, 2, 10, 3, 15
    i starts at 0 and goes up by 1 each pass, so i * 5 goes 0, 5, 10, 15. The first line is 0 long, so you never see it.
  3. Work out the turn: A program has sides = 8 and turns right(360 / sides) on every pass of its loop. How many degrees is each turn?
    45
    360 / 8 = 45. The name sides holds 8 each time the line runs.

Solutions

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

Modify › Grow faster

from turtle import *

for i in range(30):
    forward(i * 10)
    right(90)

Modify › Thicker and thicker

from turtle import *

for i in range(30):
    pensize(i + 1)
    forward(i * 5)
    right(90)

Stretch and support

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.

Exit ticket

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.

What each step is for

Where it leads

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.