← Teacher guides

Teacher guide: Python Foundations with Turtle

Learn Python by drawing with a turtle.

Open the student course

Each lesson works two ways. Students can work through the online tutorial at their own pace (it checks their answers and saves their progress in their browser), or you can teach it to the whole class from the slides, then send students into the tutorial for the Modify and Make steps.

Every lesson guide has plain-language notes, the answers to every check, a solution for every task, and slides and a worksheet for Waypoints Prepare. These guide pages are not linked from student pages, but they are not secret either: keep printed Teacher editions for answers you do not want students to find.

Whole-course cheat sheet: Open to print (every command, grouped by unit: a handout for the final challenge)

Commands, loops and values

Commands, loops, names, the counter and updates, one idea at a time.

Commands, loops and variables in 5 minutes (read before teaching this unit)

The idea in plain words

A program is a list of instructions the computer follows in order, top to bottom. forward(100) moves the turtle 100 steps; right(90) turns it a quarter turn.

A loop repeats the lines indented under it: for i in range(4): means "do these lines 4 times". A variable is a name for a value: sides = 5 stores 5 under the name sides, and the program uses 5 wherever it sees sides.

Why programmers use them

  • Loops stop programs growing with every repeat. A 4-sided and a 100-sided shape are both 3 lines with a loop.
  • Variables put a value in one place. Change sides once and every line that uses it follows. They can also hold calculations: angle = 360 / sides works out the turn for you.

An everyday picture, and where it breaks

A loop is a recipe step that says "stir 4 times". A variable is a labelled jar: the label stays, the contents can change.

Where it breaks: in maths, x = x + 5 is impossible. In Python = means store, read right to left: work out x + 5, then put the answer back in x. Say "store" aloud instead of "equals" and students follow.

Try it yourself (5 minutes)

  1. Open the Python playground and run forward(100) then right(90), four times.
  2. Replace them with for i in range(4): and the two lines indented under it. Same square.
  3. Add sides = 6 at the top, use range(sides) and right(360 / sides). Change sides to 3, then 12.

Questions students ask

  • "Why does it turn 120, not 60, for a triangle?" The turtle turns at the outside of each corner. All the turns add up to one full turn, 360, so 360 ÷ 3 = 120.
  • "Why do the lines have to be pushed in?" Indentation tells Python which lines belong to the loop.
  • "Why doesn't size = size + 5 break?" It works out the right side first, then stores the result back in size.

How it connects

Loops and variables appear in every later lesson. Next unit adds choices (if) and lists; later, functions give a group of steps a name.

Cheat sheet: Open to print (A4, with a picture of what each command draws) · Markdown

Choices and lists

Decisions, patterns, lists and for-each, then a challenge: make a tile.

Decisions and lists in 5 minutes (read before teaching this unit)

The idea in plain words

A decision lets the program choose. if score > 10: asks a question; the indented lines under it run only when the answer is yes, and the lines under else: run when it is no. elif asks another question when the first answer was no.

A list keeps many values in order under one name: colours = ["red", "blue", "green"]. for c in colours: takes them one at a time. Each item has a place, counted from 0: colours[0] is the first.

Why programmers use them

  • Decisions are how programs respond: a traffic light, a passing score, a correct password.
  • Lists keep data separate from instructions. Add a colour to the list and the loop draws one more square, with no change to the code.

An everyday picture, and where it breaks

An if is a fork in a path with a sign: "if it is raining, take the left path". A list is a numbered row of lockers.

Where it breaks: the lockers start at number 0, not 1. A list of 5 items has places 0 to 4, and asking for place 5 is an error. Expect this surprise; it is the most common list bug.

Try it yourself (5 minutes)

  1. In the playground, run print(7 % 2) and print(8 % 2). % is the remainder after dividing (not percent): 1 for odd numbers, 0 for even.
  2. Write a loop for i in range(6): with if i % 2 == 0: print("even") and else: print("odd") under it.
  3. Make colours = ["red", "blue", "green"] and print(colours[1]). It prints blue.

Questions students ask

  • "Why two equals signs?" One = stores a value. Two == ask whether two things are equal.
  • "Why does my list start at 0?" The place number counts how far an item is from the start. The first item is 0 steps away.
  • "What does the colon do?" It ends the question line. The indented lines below are what happens.

How it connects

Decisions are the hit test in Build a button and the rules in the final game. Lists hold the game's path and the buttons on a control panel.

Cheat sheet: Open to print (A4, with a picture of what each command draws) · Markdown

Open projects

Self-paced briefs students can pick up after the lesson named on each. Students tick their own milestones and claim a badge; the page lights the skills their code uses. Badges stay in the student's browser: ask them to press Show your teacher. Open the projects page

Pattern maker (after turtle-every-other; the loop counter used inside the loop, if, remainder (%), change a variable from itself (x = x + 1, +=))

Make a pattern that changes as it goes: stripes, a checkerboard, a row of tiles that swap colour, or a spiral that switches every third turn. The rule for what changes is yours.

Milestones:

  • It runs and draws a pattern with at least 8 parts.
  • Something changes as the loop goes on (colour, size or shape), decided by an if.
  • I changed one number and the pattern changed the way I expected.

A first open brief: everything it needs is in lessons 1 to 3. Students who stall usually have no rule yet: ask them to say the rule aloud ("every second square is red") before they code it.

One possible solution
from turtle import *

speed(0)
penup()
goto(-200, 0)
size = 20

for i in range(12):
    if i % 3 == 0:
        fillcolor("gold")
    elif i % 3 == 1:
        fillcolor("tomato")
    else:
        fillcolor("teal")
    pendown()
    begin_fill()
    for side in range(4):
        forward(size)
        left(90)
    end_fill()
    penup()
    forward(size + 6)
    size = size + 2