Run the coloured shape. The idea to have ready: the first item in a list is in place 0, so a list of 5 items has places 0 to 4. Asking for place 5 stops the program with an IndexError.
Running the lesson
Predict: ask what colour the third side is. Many say orange: they count the places from 1. Do not correct it yet; run it and let the picture do the work.
Run: read colours[i] aloud as 'the colour in place i'. Ask: what is i on the first pass, and so which colour?
Investigate: students say which item is in each place before running. The number question is the same idea backwards: the last place is one less than the length.
Modify: adding colours changes the picture without touching the loop. Ask why that is useful (the data changes, the instructions do not).
Mix it up: the turn is worked out from len, so it changes when the list does.
The hard part (on purpose)
Places start at 0, so the last place is one less than the length. Ask how many items there are and what the last place number is.
When students get stuck
An IndexError: list index out of range. Ask: How many items are in the list, and what is the last place number? Fix: The last place is one less than the length. Loop with range(len(colours)) so the count always matches.
A NameError, or the colour name is printed instead of used. Ask: Does every colour have quotes round it, with commas between them? Fix: Text in a list needs quotes: ["red", "blue"].
A student expects colours[1] to be red. Ask: What is the place of the very first item? Fix: The first place is 0. colours[0] is red, colours[1] is orange.
Stretch and support
Stretch: Make a second list of sizes and use sizes[i] alongside colours[i], so each side has its own colour and length.
Support: Give students the list on paper with the places written under each item, and ask them to point to colours[2] before running the program.
Where it leads
Next lesson visits every item without counting places: a for-each loop. Lists return in the game's path and the buttons of a control panel. Playlists, class rolls and leaderboards are lists.
What each step is for
Investigate: A list is numbered from 0, so the last place is one less than the length, and asking for a place that does not exist stops the program.
Modify: Changing a list changes the whole result with no change to the loop, which is why the data and the instructions are kept apart.
Mix it up: Names, the counter and a list work together: the list holds the values, the counter picks one, and len keeps the loop in step.