←Previous page

13TURTLE DRAWING · MOVES

A turtle that draws.

The turtle walks on the screen and leaves a line behind it. You tell it every step.

IN REAL LIFE

Steps and turns draw a path.

Walk, turn, walk again. You already give directions like this.

Directions to a friend

"Walk to the corner, turn left, walk two more houses."

A robot vacuum

It drives straight, turns in place at the wall, then drives again.

A toy car with a marker

Tape a marker to it. Wherever it rolls, it leaves a line on the paper.

LOOK FIRST

How the turtle moves.

Start in the middle

A new turtle stands in the middle of the screen, facing right.

Walk forward

forward(100) walks 100 steps the way it faces and draws a line.

Turn in place

left(90) and right(90) turn without walking. 90 is one corner.

LOOK FIRST

Read it line by line.

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

PyBot's first drawing.

Guess first. Then run real Python and check.

1

Guess the result

import turtle t = turtle.Turtle() t.forward(150) t.left(90) t.forward(150)

What will the turtle draw?

draw.pyREAL PYTHON
OUTPUT
Ready. Press Run Python.
Python runs here thanks to Pyodide ♥

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

Walk, turn, draw.

Try each tiny question. A wrong answer becomes something to review.

0Completed
12Not tried
0Review
01

Like the turtle in real life

The turtle walks where you say and leaves a line.

Which one works like the turtle?

02

Where does it start?

import turtle t = turtle.Turtle()

Where is the new turtle, and which way does it face?

03

What does left do?

t.left(90)

What does the turtle do?

04

Two turns

t.left(90) t.left(90)

The turtle starts facing right.

Which way does it face now?

05

Turn right, then walk

t.right(90) t.forward(50)

The turtle starts facing right.

Which way does the line go?

06

Pen up, pen down

t.forward(50) t.penup() t.forward(50) t.pendown() t.forward(50)

What do you see on the screen?

07

Where does it end?

t.forward(100) t.left(180) t.forward(100)

Where is the turtle at the end?

08

Color and size

t.color("red") t.pensize(8) t.forward(80)

What line appears?

09

Fix PyBot's code

PyBot wants a stair step: right, up, then right again. One turn is missing.

Goal drawingYour drawingOUTPUT

10

Fix PyBot's code

PyBot paints a dashed road with two gaps, but one gap is missing. Lift the pen there.

Goal drawingYour drawingOUTPUT

11

Fix PyBot's code

The flag pole should go up, but the turtle draws it going down. Fix the first turn.

Goal drawingYour drawingOUTPUT

Your work is saved here.

Want a fresh start? Clear only this page.

!
BIG IDEA

The turtle draws every step you give it.

forward walks, left and right turn in place, and penup and pendown decide if the walk leaves a line.