KS3 & GCSE Computing · Key Stage 3

Python Turtle Graphics for KS3 Computing: Shapes, Loops and Colours

Learn Python turtle graphics for KS3 computing: drawing shapes, using loops to create patterns, changing pen colour, and writing your first turtle programme.

Duke Harewood — author of AI Tutors for Key Stage 3Updated 3 min read

On this page

Short answer

Python's turtle module gives you a virtual pen — called the turtle — that moves around a screen leaving a trail. By giving it commands such as forward(100) and left(90) you can draw any geometric shape. Turtle graphics is an excellent way to practise loops, functions, and coordinates in a visual, immediately rewarding environment at KS3.

At a glance

Key stage
Key Stage 3
Subject
Computing
Type
How-to guide
For
Students
Read time
3 min
Last updated
21 October 2026

Where this fits

  1. Key Stage 3Years 7–9This article
  2. GCSEYears 10–11
This article is aimed at Key Stage 3 (Years 7–9), the stage before GCSE (Years 10–11).

Method at a glance

  1. Import the module and set up the screen
  2. Set the pen colour and size
  3. Use a loop with the correct angle for your shape
  4. Call turtle.done()
The 4 numbered steps in this article, in order.

What is the turtle and how does it move?

The turtle starts at the centre of a drawing window, facing right (east), with its pen touching the canvas. Every move command draws a line unless you lift the pen first.

The four basic movement commands are:

  • turtle.forward(distance) — move forward in the current direction by distance pixels.
  • turtle.backward(distance) — move backward.
  • turtle.left(angle) — turn left (anti-clockwise) by angle degrees.
  • turtle.right(angle) — turn right (clockwise) by angle degrees.
import turtle

turtle.forward(100)   # draw a 100-pixel line heading right
turtle.left(90)       # turn to face upward
turtle.forward(100)   # draw another 100-pixel line

This produces an upside-down L shape.

How do you draw a square using a loop?

A square has four equal sides and four 90° turns. Rather than typing four pairs of commands, use a for loop:

import turtle

for side in range(4):
    turtle.forward(100)
    turtle.left(90)

turtle.done()   # keeps the window open

This is the turtle graphics embodiment of the computational thinking concept of abstraction — the pattern (forward + turn) is identical four times, so you generalise it into a loop.

Exterior angles of regular polygons:

Shape Sides Exterior angle turtle.left(angle)
Equilateral triangle 3 120° left(120)
Square 4 90° left(90)
Regular pentagon 5 72° left(72)
Regular hexagon 6 60° left(60)
Regular n-gon n 360/n left(360/n)

The rule is: the exterior angle of a regular n-sided polygon equals 360 ÷ n.

How do you draw a complete turtle programme step by step?

Follow these steps to write a programme that draws a coloured star:

  1. Import the module and set up the screen. Call import turtle and optionally turtle.bgcolor("black") to set a background colour.
  2. Set the pen colour and size. Use turtle.pencolor("yellow") and turtle.pensize(3) to style the line.
  3. Use a loop with the correct angle for your shape. A five-pointed star uses 5 iterations with forward(150) and right(144) — the exterior angle is 144° (the supplement of the interior angle of a pentagram).
  4. Call turtle.done(). This keeps the window visible after the drawing completes; without it the window closes immediately on some systems.
import turtle

turtle.bgcolor("black")
turtle.pencolor("yellow")
turtle.pensize(3)
turtle.speed(5)       # drawing speed 1 (slowest) to 10 (fastest)

for point in range(5):
    turtle.forward(150)
    turtle.right(144)

turtle.done()

How do you use penup() and pendown() to draw without leaving a trail?

turtle.penup() lifts the pen off the canvas — the turtle can then move without drawing. turtle.pendown() puts the pen back. This is useful for drawing separate shapes.

import turtle

# Draw first square
for _ in range(4):
    turtle.forward(80)
    turtle.left(90)

turtle.penup()
turtle.forward(120)   # move right without drawing
turtle.pendown()

# Draw second square
for _ in range(4):
    turtle.forward(80)
    turtle.left(90)

turtle.done()

How do you create spiral and fractal patterns with nested loops?

A spiral can be created by increasing the forward distance on each iteration:

import turtle

for step in range(36):
    turtle.forward(step * 5)   # each side is 5 pixels longer than the last
    turtle.left(91)            # 91° instead of 90° creates a spiral rather than a closed square

turtle.done()

Changing left(91) to left(89) reverses the spiral direction. Changing the multiplier (5) changes how tightly the spiral expands. Experimenting with these numbers is the algorithmic version of sketching — adjusting a parameter and observing the effect builds intuition for how algorithms produce outputs.

Frequently asked questions

Why does turtle.done() need to go at the end?

turtle.done() (also called turtle.mainloop()) hands control to the turtle graphics window's event loop, which keeps the window alive and responsive until the user closes it. Without it, the Python script finishes and Python closes the window almost instantly — your drawing disappears before you can see it. Always place turtle.done() as the final line of a turtle programme.

Can I change the turtle's shape and speed?

Yes. turtle.shape("turtle") changes the cursor icon to a small turtle (other options: "arrow", "circle", "square"). turtle.speed(0) draws instantly (no animation); turtle.speed(1) is very slow. For debugging and learning, a medium speed (turtle.speed(5)) lets you watch the drawing build step by step.

What is the difference between turtle.color() and turtle.pencolor()?

turtle.pencolor("red") sets only the line colour. turtle.fillcolor("blue") sets only the fill colour. turtle.color("red", "blue") sets both at once — pen colour first, fill colour second. To actually fill a shape with colour, you must call turtle.begin_fill() before drawing and turtle.end_fill() after.

How does turtle graphics relate to coordinates?

The turtle window uses a Cartesian coordinate system with the origin (0, 0) at the centre. You can move the turtle directly to any coordinate using turtle.goto(x, y). Positive x is to the right; positive y is upward — the same convention you use in KS3 mathematics. Understanding that forward(100) at angle 0° moves from (0,0) to (100, 0) links programming commands directly to mathematical coordinate geometry.


For Socratic KS3 tutoring and free GCSE flashcards, see aitutors.me.

Key terms

  • turtle
  • turtle.forward(distance)
  • turtle.backward(distance)
  • turtle.left(angle)
  • turtle.right(angle)
  • abstraction
  • Call turtle.done()
  • turtle.penup()

Sources