1) What do I need to do?
π― Your mission: Loop a square
Draw a square using a for loop (no copying the same lines 4 times!).
2) What do I need to know?
Meet the turtle
Turtle is a library that gives you a little drawing robot. It carries a pen and draws wherever it goes!
forward(100) moves 100 steps. left(90) turns left 90 degrees (a quarter turn). right(90) turns right.
The middle of the screen is (0, 0). Run the example and watch it draw!
π§° Your toolkit for this mission
Everything you need to know to finish this lesson on your own:
Set up the turtle
Import the library and make a turtle robot.
How to write it: import turtle then t = turtle.Turtle().
import turtle t = turtle.Turtle()
Moving
The turtle draws a line wherever it moves.
How to write it: t.forward(100) moves 100 steps β’ t.right(90) / t.left(90) turn by degrees.
t.forward(100) t.right(90)
Shapes with loops
A square is 4 Γ (forward, turn 90).
How to write it: Any shape: turn by 360 / sides each time.
for i in range(4):
t.forward(100)
t.right(90)Colours & pens
Change how lines look.
How to write it: t.color("red") β’ t.pensize(5) β’ t.penup() / t.pendown() to move without drawing.
t.color("gold")Filled shapes & circles
Colour in a shape, or draw a circle.
How to write it: t.begin_fill(), draw, t.end_fill() β’ t.circle(50) draws a circle of radius 50.
t.fillcolor("red")
t.begin_fill()
t.circle(50)
t.end_fill()Function shapes
Wrap a shape in a function with parameters.
How to write it: def polygon(sides, size): with a loop of sides and turn 360 / sides.
def polygon(sides, size):
for i in range(sides):
t.forward(size)
t.right(360 / sides)Think about it
Look at this code. What happens next, and why? Say it in your own words.
t.left(90) t.forward(80)
Watch & explore βΆ
Power-up: Meet the turtle
See it happen
1 / 3import turtle t = turtle.Turtle()
The turtle carries a pen and starts at the centre, facing right.
3) Run the code & terminal output
Press βΆ RUN and your program's messages appear here!


Captain Py
Our next adventure is yours to create.
