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.
Setting up and moving
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
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
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
x increases to the right and y increases upwards, as on a graph.
A turtle starts at (0, 0) facing right. It runs forward(50), right(90), forward(20), right(90), forward(10). Where does it finish?
- forward(50): (50, 0), facing right.
- right(90): now facing down. forward(20): (50, -20).
- right(90): now facing left. forward(10): (40, -20).
Answer: (40, -20)
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.
Try two quick questions
See if it has sunk in. Answers are marked straight away.
2 more questions
Try each one, then tap to check.
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°.
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.
- Pearson Edexcel GCSE Computer Science (1CP2) specification, topic 6.6.1, 6.2.2
- Pearson Edexcel GCSE Computer Science (1CP2) sample assessment materials and Programming Language Subset
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? →