Give a turtle commands, in order, and watch the picture they make.
Every animation, game character and robot is moved by a list of commands that run in order. Today you give the commands.
A turtle walks across the screen, leaving a line behind. Your program tells it where to go. By the end you will draw digits, the way a calculator or a digital clock does.
Predict: Read the code and say what it will do before you run anything. A wrong guess is fine: it shows you what to look for.
Run: Run it and compare the result with your prediction.
Investigate: Trace how each line of code connects to what you see.
Make: Build something new using what you have learned. Expect a few tries; that is normal.
Make your prediction first. Help opens once you've locked it in.
Info
Meet the commands
A program is a list of commands. The turtle follows them one at a time, from the top down.
Line
What it does
Why
from turtle import *
Gives your program the turtle commands
Copy this to the top of every program for now. A later lesson shows how it works
forward(100)
Moves the turtle 100 steps and draws a line
The number is how far
right(90)
Turns the turtle a quarter turn clockwise, on the spot
It does not move or draw. 90 is a quarter of a full turn
left(90)
Turns the turtle a quarter turn the other way
Also on the spot, also no line
forward(100)
Moves again, now in the new direction
The turn changed which way is forward
The turtle starts in the middle, facing right. The order matters: swap two lines and you get a different picture.
Meet the commands · Sound on for the voiceoverVoice:
PredictRead the code and say what it will do before you run anything. A wrong guess is fine: it shows you what to look for.
Show the picture to matchThe picture to match · Sound on for the voiceoverVoice:
These five lines are mixed up. Put them in the order that draws the picture.
Pieces (click to add)
Your program
MakeBuild something new using what you have learned. Expect a few tries; that is normal.
Make
Draw a 4 like the one on a calculator: a short stroke down, a bar across, then one long stroke from top to bottom. Use bars of 50 steps. The turtle may draw over a line it has already drawn, so you do not need to lift the pen.
Try it yourselfYour edits are saved in this browser.
Need a hint?
Start at the top left. The first stroke goes down 50, then across 50 to the right, then up 50 to the top.
Another hint
You can go back over a line you already drew. After the stroke up, turn right twice (right(180)) and go down 100 for the long stroke.
Show what the 4 should look likeThe expected result: the digit 4 · Sound on for the voiceoverVoice:
Draw a 4 with forward, left and right.
Run your program. This ticks when your code does all of the above.
For teachers
Students meet the turtle, read a program that draws a digital 2, learn that the order of commands is the picture, and draw a 4 themselves. About 35 minutes.
I can say what forward, right and left do to the turtle.
I can say why the order of the commands matters.
I can write a program of several commands that draws a digit.
Before class
Draw the 4 yourself. It takes two minutes, and you will see why the last turn is right(180).
Running the lesson
Meet the commands: you explain, at the board. Run the three lines live, one at a time. Say what forward and right do, that right does not move the turtle, and that left turns the other way.
Predict: show the digit-2 program and take a vote before anyone runs it. Ask students to walk it as the turtle. The wrong options are two slips: thinking the turns draw, and mixing up right with left.
Run: run it on the slide, then students run it themselves. Ask: which lines drew, and which only turned?
Put the lines in order: students do the ordering on their own screens. Circulate; if a student is stuck, ask which way the turtle is facing after the first turn.
Make: the 4. Hints are in the speaker notes. If the room is unsure, model the first stroke on the board and let students write the rest. The last stroke goes over a line already drawn, which is allowed.
The hard part (on purpose)
Remembering that right and left turn without drawing. Ask what the turtle did on that line, instead of telling them.
When students get stuck
The turtle draws a line where the student expected a turn. Ask: Does right(90) move the turtle, or only turn it? Fix: right and left turn the turtle on the spot. Only forward draws.
The 4 comes out back to front, or the strokes point the wrong way. Ask: Read the lines aloud in order, as if you were the turtle. Where does it face after each turn? Fix: Each line happens after the one above it, and each turn changes which way forward goes. Swap a left for a right, or the other way, and see.
A NameError or "forward is not defined". Ask: What is the first line of your program? Fix: Every program starts with from turtle import *. Copy it to the top.
Stretch and support
Stretch: Draw a second digit beside the first, such as an 8 or a 7. Where does the turtle have to start?
Support: Give the first stroke and the first turn, and ask the student to add the rest.
Where it leads
Next lesson: the same commands again and again. A square is eight lines written out, and a loop makes it three.
What each step is for
Put the lines in order: The order of the commands is the picture: the same lines in a different order make a different drawing.
Now you can
Say what forward, right and left do to the turtle.
Say why the order of the commands matters.
Write a program of several commands that draws a digit.