Turtle graphics

Python's turtle library draws pictures by moving a pen around the screen. It is in Pearson's Programming Language Subset, and recent Paper 2 exams have included a turtle question.

Practise this lesson free (7 questions)

Setting up and moving

Import the library and create a turtle. The turtle starts at (0, 0), the centre of the window, facing right (east), with its pen down.
forward(steps) and back(steps) move it. left(degrees) turns anticlockwise and right(degrees) turns clockwise.
import turtle
pen = turtle.Turtle()
pen.pencolor("blue")
for side in range(4):
pen.forward(100)
pen.right(90)
turtle.done()
This draws a blue square with sides of 100 and finishes back at (0, 0), facing right. turtle.done() keeps the window open.

Regular shapes

To draw a regular shape with n sides, repeat n times: move forward, then turn by 360 ÷ n degrees (the exterior angle). A triangle turns 120°, a square 90°, a hexagon 60°.
import turtle
pen = turtle.Turtle()
sides = 6
for side in range(sides):
pen.forward(50)
pen.left(360 / sides)
turtle.done()

Pen, colour and position

penup() lifts the pen so the turtle moves without drawing; pendown() puts it back. pencolor() and pensize() change the line.
For a filled shape: fillcolor(), then begin_fill(), draw the shape, then end_fill().
setposition(x, y) moves to a point (it draws a line if the pen is down). setheading(degrees) points the turtle: 0 is right, 90 is up, 180 is left, 270 is down. home() returns to (0, 0).
import turtle
pen = turtle.Turtle()
pen.fillcolor("red")
pen.begin_fill()
for side in range(3):
pen.forward(120)
pen.left(120)
pen.end_fill()
pen.penup()
pen.setposition(-150, 0)
pen.pendown()
turtle.done()

Tracing a turtle

Keep track of the position and the direction. Facing right, forward(80) goes to (80, 0). left(90) now faces up, so forward(30) goes to (80, 30).
x increases to the right and y increases upwards, as on a graph.
Worked example

A turtle starts at (0, 0) facing right. It runs forward(50), right(90), forward(20), right(90), forward(10). Where does it finish?

  1. forward(50): (50, 0), facing right.
  2. right(90): now facing down. forward(20): (50, -20).
  3. right(90): now facing left. forward(10): (40, -20).

Answer: (40, -20)

Key idea

A turtle starts at (0, 0) facing right with its pen down. forward and back move it; left turns anticlockwise and right clockwise. A regular n-sided shape turns 360 ÷ n each time. penup stops drawing; begin_fill and end_fill fill a shape.

Quick check

Try two quick questions

See if it has sunk in. Answers are marked straight away.

Extra practice

2 more questions

Try each one, then tap to check.

  1. A turtle program draws a regular hexagon (6 sides). By how many degrees must it turn after each side?

    Show the answer

    Answer: 60 °

    The turns add up to 360°: 360 ÷ 6 = 60°.

  2. What total length of line does this draw?
    import turtle
    pen = turtle.Turtle()
    for side in range(4):
    pen.forward(55)
    pen.left(90)
    turtle.done()

    Show the answer

    Answer: 220

    The loop draws 4 sides of 55: 4 × 55 = 220.

Check you have got it

Answer 7 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.

Video for this lesson coming soon. Subscribe on YouTube

Sources and references

Checked by the GCSE-ready editorial team, 16 October 2026. Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.

What do exam command words like explain and evaluate mean? →

Related lessons