← Teacher guide

Challenge: a tile

Students read a tile pattern that combines loops, names, a list and the remainder, change it, and make a tile of their own.

Python Foundations with Turtle · Choices and lists · about 40 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 8 min · Investigate 8 min · Modify 8 min · Make 16 min

Before class

Run the tile, then make a checkerboard yourself. The tricky part is backward(size * 4) at the end of a row: it must match the number of columns.

Running the lesson

  1. Predict and Run: the count is rows times columns. Ask students to say which loop is which.
  2. Investigate: students work out the colour of one square on paper. The remainder is what makes the pattern repeat.
  3. Modify: insist on a prediction before each run. Ask students to say what they expect, then check.
  4. Make: let students plan on paper first. Early finishers add a second decision, or a list of sizes.

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)

Planning the pattern before coding. Ask them to colour a small grid on paper and say the rule in words first.

When students get stuck

What you will seeA question to askThe fix
The rows do not line up, or each row starts further right.How far does the turtle move along a row, and how far does it come back?Come back by size times the number of columns: backward(size * 5) for 5 columns.
An IndexError on the colours line.Is the place always less than len(colours)?Use the remainder with len(colours): (row + col) % len(colours).
The tile is one colour.What does the decision depend on? Does it change as row and col change?The condition must use row or col, or the remainder of them.

Answers to the checks

  1. Predict: How many squares will the program draw?
    12. The outer loop makes 3 rows and the inner loop makes 4 squares in each row, so 3 × 4 = 12.
  2. Follow one square: In row 0, column 1, what is pick?
    1
    row + col is 0 + 1 = 1, and 1 % 3 is 1. colours[1] is navy.
  3. Change the list: colours has 4 colours instead of 3. What is pick in row 2, column 3?
    1
    row + col is 5, and 5 % 4 is 1. A longer list changes the remainder, so the pattern repeats more slowly.

Solutions

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

Modify

from turtle import *

colours = ["gold", "navy", "teal", "tomato"]
size = 40
speed(0)

penup()
goto(-100, -80)
for row in range(4):
    for col in range(5):
        pick = (row + col) % len(colours)
        fillcolor(colours[pick])
        begin_fill()
        for side in range(4):
            forward(size)
            right(90)
        end_fill()
        forward(size)
    backward(size * 5)
    left(90)
    forward(size)
    right(90)

Make

from turtle import *

colours = ["pink", "purple", "teal"]
size = 30
speed(0)

penup()
goto(-90, -60)
for row in range(4):
    for col in range(6):
        if (row + col) % 2 == 0:
            fillcolor(colours[col % len(colours)])
        else:
            fillcolor("white")
        begin_fill()
        for side in range(4):
            forward(size)
            right(90)
        end_fill()
        forward(size)
    backward(size * 6)
    left(90)
    forward(size)
    right(90)

Stretch and support

Stretch: Make the tile grow: each square a little bigger than the one before, using an update.

Support: Give the working tile and ask the student to change only the list of colours, then only the size.

Exit ticket

A grid has 5 rows and 6 columns. How many squares is that, and which line would you change to get 8 columns?

30 squares. Change the number in the inner loop, range(6), and the backward(size * 6) line to match.

What each step is for

Where it leads

Course B starts from a working program and builds up to a game: functions, modules and events. Class ideas: print the tiles and arrange them in a class wall.