Before We Begin · Turtle Needs a Real Window
One-timeThe turtle module opens a graphics window — so it needs a desktop Python install, not the online editor. If you set up Path A (Python + VS Code) back in PY-L1-01, you're ready.
If you only used online-python.com, two options:
- Install Python locally — follow Path A from PY-L1-01. One-time cost.
- Use Replit (replit.com) — "Turtle Console" templates work in the browser.
Test your install with this one-liner. If a window opens with a triangular arrow in it, you're good.
import turtle turtle.forward(100) turtle.done()
Learning Goals
3 minBy the end of this lesson you can:
- Open a turtle window and move the turtle with
forward,backward,right,left. - Pick up and put down the pen with
penup()/pendown()to move without drawing. - Change the turtle's speed and shape.
- Keep the window open with
turtle.done()at the end of every script.
Warm-Up · The Turtle is a Robot
5 minImagine a friendly robot turtle holding a pen, sitting in the middle of a sheet of paper. It only understands four commands:
- forward(distance) — walk that many steps, dragging the pen.
- right(angle) — turn right by that many degrees.
- left(angle) — turn left.
- backward(distance) — walk backwards.
That's it. With those four, you can draw any shape made of straight lines. The trick is choosing the right sequence.
import turtle turtle.forward(100) turtle.right(90) turtle.forward(100) turtle.right(90) turtle.forward(100) turtle.right(90) turtle.forward(100) turtle.done()
What does this draw?
A square, 100 units on a side. right(90) turns 90° each time — four times — making a closed square.
Turtle programming is just "tell a robot how to walk while holding a pen". Every shape decomposes into walk-then-turn.
New Concept · The Turtle Command Set
14 minMovement
import turtle as t t.forward(80) # alias: fd(80) t.backward(40) # alias: bk(40) t.right(90) # alias: rt(90) t.left(45) # alias: lt(45)
import turtle as t shortens every call. You'll see both styles in real code.
Pen control
By default the turtle drags the pen. Lift it to move without drawing.
t.penup() t.forward(100) # moves but draws nothing t.pendown() t.forward(50) # draws again
Speed and look
t.speed(0) # 1 (slowest) → 10 (fast) → 0 (no animation) t.shape("turtle") # the cursor — also "arrow", "circle", "classic" t.pensize(3) # line thickness t.color("blue") # pen colour by name t.bgcolor("ivory")# background colour
speed(0) skips the animation — useful for big drawings; otherwise you'll watch a turtle plod for ten minutes.
Position and heading
t.goto(0, 0) # absolute position (x, y) t.setheading(0) # point right (east). 90 = up, 180 = left, 270 = down t.home() # go back to (0, 0) with heading 0 print(t.position()) # current (x, y) as a tuple print(t.heading()) # angle the turtle is pointing
The closer · turtle.done()
Always end with turtle.done(). Otherwise the window closes the instant the script finishes and you see nothing.
import turtle turtle.forward(100) turtle.done() # ← without this, the window flashes and dies
The coordinate system
The window's centre is (0, 0). X grows to the right, Y grows up — like maths class, not like screen pixels. The default window is roughly 600×600.
The full cheat-sheet
MOVE forward(n) fd(n) backward(n) bk(n)
TURN right(deg) rt(deg) left(deg) lt(deg)
PEN penup() pu() pendown() pd()
LOOK color("red") pensize(3) shape("turtle")
SCREEN bgcolor("ivory") speed(0)
POSITION goto(x, y) home() setheading(deg) position()
END turtle.done() ← always lastWorked Example · Your Initial
12 minThe story
Draw the capital letter L — two strokes, no loops. Then add your own first initial below it. Both need the penup/pendown trick to move without drawing.
Save as my_initial.py:
# my_initial.py — draw an L import turtle as t t.speed(3) t.pensize(5) t.color("teal") # The vertical down-stroke of L t.left(90) # face up t.backward(200) # actually moves down (since we faced up) # easier mental model: # t.setheading(270) # t.forward(200) # The horizontal stroke t.setheading(0) t.forward(100) # Lift, move below, draw the date t.penup() t.goto(150, -100) t.pendown() t.color("steelblue") t.write("Aisyah, 2026", font=("Arial", 14, "normal")) t.done()
Two things to notice. (1) Using setheading + forward is often clearer than mixing forward/backward with relative turns — try both. (2) t.write(...) drops text at the turtle's current position — a quick way to label a drawing.
What you'll see
A teal capital L, big and bold, with your name written in steel blue beside it. Tweak the numbers — bigger, smaller, different colours.
For the first 32 lessons your code talked to the user. Today, the same loops and variables move a pen on a canvas. You've traded print() for forward() — but the thinking is the same.
Try It Yourself
13 minDraw an equilateral triangle (three sides of 100 each). The interior angles are 60°, so the turtle turns by 120° at each corner.
Hint
import turtle as t for _ in range(3): t.forward(100) t.left(120) t.done()
Why 120 and not 60? The turtle turns by the exterior angle. For any regular polygon, exterior angle = 360 / sides. We'll formalise this in PY-L2-34.
Draw a plus sign (+) made of two perpendicular lines through the centre, each 100 units long.
Hint
import turtle as t # Horizontal stroke t.penup(); t.goto(-50, 0); t.pendown() t.forward(100) # Vertical stroke t.penup(); t.goto(0, -50); t.pendown() t.setheading(90); t.forward(100) t.done()
The penup → goto → pendown pattern is how you start a new stroke from a different position.
Draw a simple house: a square for the body, a triangular roof on top, a door rectangle inside the square. Pick your own dimensions.
Hint · plan
Three sub-shapes. Start at the bottom-left corner of the square. Draw the square (four sides). Then position at the top-left and draw the roof triangle. Finally, position inside the square and draw the door. Use lots of penup/pendown between sub-shapes.
import turtle as t # Body (square) for _ in range(4): t.forward(150) t.left(90) # Roof — turtle is now back at start, facing right t.setheading(60) t.forward(150) t.right(120) t.forward(150) # Door t.penup() t.goto(50, 0) t.setheading(90) t.pendown() for _ in range(2): t.forward(60); t.right(90) t.forward(30); t.right(90) t.done()
Mini-Challenge · Five-Pointed Star
8 minDraw a five-pointed star without a loop. (You'll use a loop in PY-L2-34 — today just type the five sides.)
The trick: at each point of the star, the turtle turns by 144°. Try it.
Show one possible solution
# star.py — manual five-pointed star import turtle as t t.speed(3) t.color("crimson") t.pensize(3) t.forward(150); t.right(144) t.forward(150); t.right(144) t.forward(150); t.right(144) t.forward(150); t.right(144) t.forward(150); t.right(144) t.done()
Non-negotiables: five forwards and five 144° right turns. Why 144°? Because in a five-pointed star the exterior angle at each point is 144° (the interior angle is 36°). The shape closes naturally because 5 × 144° = 720° = 2 full turns.
Recap
3 minThe turtle is a robot with a pen. forward, backward, right, left are the four core commands. penup/pendown lifts the pen to move without drawing. Always end with turtle.done() so the window stays open. The screen coordinate system has the origin in the centre and Y increasing upwards — the maths-class convention, not the pixel-art one.
Vocabulary Card
- turtle
- The graphics module that ships with Python. Animates a pen-holding cursor.
- forward / right / left
- The three commands that drive 90% of turtle drawings.
- penup / pendown
- Lift / lower the pen. Move without drawing / draw again.
- setheading(deg)
- Point the turtle at an absolute angle. 0 = right, 90 = up, 180 = left, 270 = down.
- turtle.done()
- Keeps the window open after your script ends. Always the last line.
Homework
4 minDraw your own monogram — your first and last initials, side by side, in two different colours. Each letter should be made of straight strokes. Add a small horizontal line under them. Save your file as monogram.py.
Stretch. Add the current year above the initials using turtle.write. Use date.today().year from PY-L2-32 to keep it fresh.
Sample · monogram.py (drawing "A · H")
# monogram.py — draw two initials side by side import turtle as t from datetime import date t.speed(5) t.pensize(4) t.bgcolor("ivory") # Year above t.penup(); t.goto(-40, 100); t.pendown() t.color("dimgray") t.write(date.today().year, font=("Arial", 18, "italic")) # Letter "A" t.color("crimson") t.penup(); t.goto(-150, -100); t.pendown() t.setheading(75); t.forward(180) t.setheading(-75); t.forward(180) # crossbar t.penup(); t.goto(-110, -25); t.pendown() t.setheading(0); t.forward(75) # Letter "H" t.color("steelblue") t.penup(); t.goto(50, -100); t.pendown() t.setheading(90); t.forward(180) t.penup(); t.goto(50, -10); t.pendown() t.setheading(0); t.forward(100) t.penup(); t.goto(150, 80); t.pendown() t.setheading(270); t.forward(180) # Underline t.color("black") t.penup(); t.goto(-150, -120); t.pendown() t.setheading(0); t.forward(300) t.done()
Non-negotiables: two different colours, multiple penup/pendown jumps to start fresh strokes, and a clean ending with turtle.done(). Your initials and colours are yours.