← Teacher guide

Read a program

Students read a longer program that combines the counter, a list, an update and a decision, find the lines that do each job, and change one part without breaking the rest.

Python functions and events · Start from a working program · about 35 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 12 min · Modify 13 min

Before class

Run the garden, then do the Modify tasks yourself. The program is a loop with a long body: that length is what the next lesson fixes.

Running the lesson

  1. Predict: read the code with the class, one comment at a time. The stem line uses the counter; ask what i is on the third pass.
  2. Run: students run it and watch which part the turtle is drawing. Ask: which lines draw a stem? Which draw a flower head?
  3. Investigate: the match task names each part's job. The bug is a reset: a value set inside the loop is set again every pass.
  4. Modify: students change one part at a time. If the extra flowers run off the screen, ask which line moves the start.

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)

Knowing which lines to change. Ask what job the new feature is, then which lines do that job.

When students get stuck

What you will seeA question to askThe fix
The extra flowers run off the screen.Where does the first flower start, and how far apart are the flowers?Move the start further left with goto, for example goto(-200, -80).
Changing one thing breaks another.Which other lines use the name you changed?Find every line that uses it before you change it. A name is used wherever it appears.

Answers to the checks

  1. Predict: stem is 50. How tall is the third stem (when i is 2)?
    70. The stem is stem + i * 10, which is 50 + 2 * 10 = 70. Each stem is 10 taller than the one before.
  2. Find the parts: Match each part of the program with its job.
    if i % 2 == 0: ... else: ... → B. alternates the stem between two greens; forward(stem + i * 10) → D. makes each stem taller than the last; head = head + 4 → A. makes each flower head bigger than the last; colours[i] → C. picks the flower's colour by its place
    Each line has one job. The if / else is a decision, i * 10 uses the counter, head + 4 is an update, and colours[i] is a list item picked by its place.
  3. Spot the bug: The flower heads should grow, but all four are the same size. Click the line that stops them growing.
    line 16
    head = 10 is inside the loop, so it is reset to 10 at the start of every pass, and the update never gets a chance to add up. Set it once before the loop.

Solutions

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

Modify › Add flowers

from turtle import *

speed(0)
colours = ["red", "orange", "pink", "purple", "gold", "teal"]
stem = 50
head = 10

penup()
goto(-200, -80)
pendown()

for i in range(len(colours)):
    if i % 2 == 0:
        pencolor("green")
    else:
        pencolor("darkgreen")
    pensize(3)
    left(90)
    forward(stem + i * 10)

    fillcolor(colours[i])
    begin_fill()
    circle(head)
    end_fill()
    head = head + 4

    penup()
    backward(stem + i * 10)
    right(90)
    forward(70)
    pendown()

Modify › Same height

from turtle import *

speed(0)
colours = ["red", "orange", "pink", "purple"]
stem = 50
head = 10

penup()
goto(-150, -80)
pendown()

for i in range(len(colours)):
    if i % 2 == 0:
        pencolor("green")
    else:
        pencolor("darkgreen")
    pensize(3)
    left(90)
    forward(stem)

    fillcolor(colours[i])
    begin_fill()
    circle(head)
    end_fill()
    head = head + 4

    penup()
    backward(stem)
    right(90)
    forward(70)
    pendown()

Stretch and support

Stretch: Make every other flower head a different shape by adding a decision to the flower-head lines.

Support: Colour or underline the lines for each job on paper before changing anything.

Exit ticket

In the garden, which part would you change to make every flower head the same size?

The update head = head + 4. Remove it, or set head once and never add to it.

What each step is for

Where it leads

Next lesson names a group of lines (a function). The garden's long loop body is the first thing to name.