Directions to a friend
"Walk to the corner, turn left, walk two more houses."
13TURTLE DRAWING · MOVES
The turtle walks on the screen and leaves a line behind it. You tell it every step.
IN REAL LIFE
Walk, turn, walk again. You already give directions like this.
"Walk to the corner, turn left, walk two more houses."
It drives straight, turns in place at the wall, then drives again.
Tape a marker to it. Wherever it rolls, it leaves a line on the paper.
LOOK FIRST
A new turtle stands in the middle of the screen, facing right.
forward(100) walks 100 steps the way it faces and draws a line.
left(90) and right(90) turn without walking. 90 is one corner.
LOOK FIRST
Moves on the left, the pen on the right.
import turtleBrings in the turtle tools.t = turtle.Turtle()Makes a turtle and keeps it in the box t.t.forward(100)Walks 100 steps to the right and draws a line.t.left(90)Turns one corner to the left. It does not walk.t.forward(50)Now it faces up, so this line goes up.t.color("blue")The pen draws in blue from now on.t.pensize(5)A thicker pen: lines are 5 wide.t.penup()Lifts the pen. The turtle walks without drawing.t.forward(40)Moves 40 steps and leaves no line.t.pendown()Puts the pen down. The next steps draw again.Color names: The turtle knows English color names in quotes, like "red", "green" or "orange".
RUN IT
Guess first. Then run real Python and check.
import turtle
t = turtle.Turtle()
t.forward(150)
t.left(90)
t.forward(150)What will the turtle draw?
PyBot's hint
Ready. Press Run Python.
Pyodide 314.0.3 runs CPython in your browser with WebAssembly.
Open-source under the Mozilla Public License 2.0. License
Now change one thing: Change left(90) to right(90) and run again. Where does the second line go now?
YOUR TURN
Try each tiny question. A wrong answer becomes something to review.
Which one works like the turtle?
import turtle
t = turtle.Turtle()Where is the new turtle, and which way does it face?
t.left(90)What does the turtle do?
t.left(90)
t.left(90)The turtle starts facing right.
Which way does it face now?
t.right(90)
t.forward(50)The turtle starts facing right.
Which way does the line go?
t.forward(50)
t.penup()
t.forward(50)
t.pendown()
t.forward(50)What do you see on the screen?
t.forward(100)
t.left(180)
t.forward(100)Where is the turtle at the end?
t.color("red")
t.pensize(8)
t.forward(80)What line appears?
PyBot wants a stair step: right, up, then right again. One turn is missing.
PyBot paints a dashed road with two gaps, but one gap is missing. Lift the pen there.
The flag pole should go up, but the turtle draws it going down. Fix the first turn.
Want a fresh start? Clear only this page.
forward walks, left and right turn in place, and penup and pendown decide if the walk leaves a line.