Drawing with Turtle: Shapes, Colors, and Loops You Can See

 

What you’ll learn in this lesson

  • What Turtle is, and why it comes free with Python
  • How to move the turtle and turn it
  • How to draw a square, then draw it with a loop
  • How to change colors and lift the pen
  • How to design a shape of your own

Meet the turtle

Turtle is a drawing tool built into Python itself — no download, no
install, it is already there. When you run a Turtle program, a drawing
window opens with a small arrow (the “turtle”) in the middle. Your
instructions move the turtle, and it draws a line wherever it walks.

Because Turtle is part of Python’s standard library, it works in IDLE
exactly like everything else in this course: write the program in a
file, run it, and watch the drawing window appear.

A note on this lesson’s code: Turtle draws pictures on screen, so its
programs cannot be run and checked on a machine with no screen the way
the other lessons’ code was. Every snippet below was checked for
correct syntax and uses only the standard Turtle commands listed in
this lesson — but you should run each one in IDLE yourself and watch
it draw, which is the whole point.


Moving and turning

Start with the two commands you will use most. forward() moves the
turtle ahead by a number of steps (think pixels on screen).
right() turns it clockwise by a number of degrees.

import turtle

t = turtle.Turtle()
t.forward(100)
t.right(90)
t.forward(100)

turtle.done()

Run this in IDLE. The turtle draws a line 100 steps long, turns right
by 90 degrees (a quarter turn), and draws a second line. Two lines, an
L shape.

Three things to understand in this snippet:

  • import turtle loads the Turtle tool. Without it, Python has no
    idea what turtle means.
  • t = turtle.Turtle() creates your turtle and stores it in the
    variable t. From now on, t.forward(...) means “my turtle, move
    forward.”
  • turtle.done() at the end keeps the drawing window open so you can
    admire your work. Without it, the window may close at once.

backward() moves the turtle back the way it faces, and left()
turns it counter-clockwise. Those four moves — forward,
backward, right, left — are enough to draw anything made of
straight lines.


A square, then a square with a loop

Four lines and four quarter-turns make a square. Written out longhand:

import turtle

t = turtle.Turtle()
t.forward(100)
t.right(90)
t.forward(100)
t.right(90)
t.forward(100)
t.right(90)
t.forward(100)
t.right(90)

turtle.done()

That works, but it repeats the same two lines four times — exactly the
problem loops were invented to solve in Lesson 9:

import turtle

t = turtle.Turtle()
for side in range(4):
    t.forward(100)
    t.right(90)

turtle.done()

Same square, in a third of the lines. The loop says “do these two
moves four times.” This is the moment loops stop being abstract: you
can see why repeating without retyping matters.


Colors and lifting the pen

color() changes the pen’s color. penup() lifts the pen so the
turtle moves without drawing; pendown() puts it back down. Together
they let you draw in several colors without connecting lines:

import turtle

t = turtle.Turtle()
t.color("red")
for side in range(4):
    t.forward(100)
    t.right(90)
t.penup()
t.forward(150)
t.pendown()
t.color("blue")
t.circle(50)

turtle.done()

Run it: a red square, then the turtle silently moves 150 steps to the
side (pen up, no line), then draws a blue circle with circle(50),
which draws a circle of radius 50. Color names are plain English
words in quotes: "red", "blue", "green", "purple", "orange".
If you misspell one, Turtle will tell you — another friendly error
message, pointing at the exact problem.


Design a shape of your own

You now know enough to invent. A triangle is three sides and three
turns of 120 degrees (because 3 × 120 = 360, a full turn). A house is
a square plus a triangle roof. A star takes five sides and 144-degree
turns — try it and see why the angle is not the obvious one.

The habit to build here is the same one from every lesson: guess,
run, look at what actually happened, and adjust. With Turtle, the
feedback is a picture, which makes the guess-and-check loop feel like
play. That is not an accident — it is why Turtle has been a
beginner’s favorite for decades.

Drawing with Turtle: Shapes, Colors, and Loops You Can See

Python for Absolute Beginners · Lesson 11

What you’ll learn

  • What Turtle is, and why it comes free with Python
  • How to move the turtle and turn it
  • How to draw a square, then draw it with a loop
  • How to change colors and lift the pen
  • How to design a shape of your own
1 / 14

Meet the turtle

  • Turtle is a drawing tool built into Python itself — no download, no install, it is already there
  • When you run a Turtle program, a drawing window opens with a small arrow (the “turtle”) in the middle
  • Your instructions move the turtle, and it draws a line wherever it walks
  • Turtle programs must be run in IDLE to be seen — the drawing appears on screen
2 / 14

Moving and turning

  • forward() moves the turtle ahead by a number of steps (think pixels on screen)
  • right() turns it clockwise by a number of degrees
  • backward() moves it back the way it faces; left() turns it counter-clockwise
  • Those four moves are enough to draw anything made of straight lines
3 / 14

Moving and turning in code

import turtle
t = turtle.Turtle()
t.forward(100)
t.right(90)
t.forward(100)
turtle.done()

Output: an L shape, drawn on screen.

Run this in IDLE: the turtle draws a line, turns right 90 degrees, and draws a second line.

4 / 14

Three things in that snippet

  • import turtle loads the Turtle tool — without it, Python has no idea what turtle means
  • t = turtle.Turtle() creates your turtle and stores it in t — from now on, t.forward(…) means “my turtle, move forward”
  • turtle.done() at the end keeps the drawing window open so you can admire your work — without it, the window may close at once
5 / 14

A square, written out longhand

import turtle
t = turtle.Turtle()
t.forward(100)
t.right(90)
t.forward(100)
t.right(90)
t.forward(100)
t.right(90)
t.forward(100)
t.right(90)
turtle.done()

Four lines and four quarter-turns make a square — but the same two lines repeat four times.

6 / 14

The same square, with a loop

import turtle
t = turtle.Turtle()
for side in range(4):
    t.forward(100)
    t.right(90)
turtle.done()

Output: the same square, drawn on screen.

Same square, in a third of the lines: “do these two moves four times.”

7 / 14

Colors and lifting the pen

  • color() changes the pen's color — color names are plain English words in quotes: “red”, “blue”, “green”, “purple”, “orange”
  • penup() lifts the pen so the turtle moves without drawing; pendown() puts it back down
  • Together they let you draw in several colors without connecting lines
  • If you misspell a color, Turtle will tell you — another friendly error message
8 / 14

Colors and penup in code

import turtle
t = turtle.Turtle()
t.color("red")
for side in range(4):
    t.forward(100)
    t.right(90)
t.penup()
t.forward(150)
t.pendown()
t.color("blue")
t.circle(50)
turtle.done()

Output: a red square and a blue circle, drawn on screen.

Run in IDLE: a red square, a silent move of 150 steps, then a blue circle of radius 50.

9 / 14

Design a shape of your own

  • A triangle is three sides and three turns of 120 degrees (3 × 120 = 360, a full turn)
  • A house is a square plus a triangle roof
  • A star takes five sides and 144-degree turns — try it and see why the angle is not the obvious one
  • The habit to build: guess, run, look at what actually happened, and adjust — with Turtle, the feedback is a picture
10 / 14

Hands-on exercise

  • Draw a square with a loop, exactly like the lesson, and run it in IDLE
  • Change the loop to draw a triangle (3 sides, 120-degree turns) and run it
  • Draw two shapes in different colors, using penup() and pendown() to move between them without a connecting line
  • Invent one shape of your own — a house, a star, or anything else — and write down how many sides and what turn angle it needed
11 / 14

Key takeaways

  • Turtle is built into Python: import turtle, then t = turtle.Turtle()
  • forward() and backward() move; right() and left() turn in degrees
  • A loop plus Turtle turns repetition into pictures you can see
  • color() changes pen color; penup() / pendown() control whether movement draws
  • circle(50) draws a circle of radius 50; turtle.done() keeps the window open
12 / 14

Take the quiz

Take the Lesson 11 quiz — 5 quick questions to check what you learned.

13 / 14

Next lesson

Lists: Many Items, Plus Indexing and Append

14 / 14

Press play on any slide and the lesson plays on by itself from there. You can still click Next or click a slide to move on.

Download the Lesson 11 slides (PowerPoint, with narration)

Download the Lesson 11 slides (PDF)


Hands-on exercise

  1. Draw a square with a loop, exactly like the lesson, and run it in
    IDLE.
  2. Change the loop to draw a triangle (3 sides, 120-degree turns)
    and run it.
  3. Draw two shapes in different colors, using penup() and
    pendown() to move between them without a connecting line.
  4. Invent one shape of your own — a house, a star, or anything else
    — and write down how many sides and what turn angle it needed.

Lesson 11: Drawing with Turtle: Shapes, Colors, and Loops You Can See

This drawing is a simulation of Turtle — run the same code in IDLE to see the real thing. The loop below is the lesson’s loop: once per side, go forward, then turn. The drawing is scaled and centred only so the shape fits this canvas.

In the lesson, a square is 4 sides with 90-degree turns, and a triangle is 3 sides with 120-degree turns. Here the turn is always 360 divided by the number of sides, so any number of sides closes neatly into a shape.


Try this: Change the sides to 3 and press Run again — the square becomes a triangle, with 120-degree turns.

The code (run this same loop in IDLE for the real Turtle drawing)



What the turtle does

Press Run to draw.

Practice file

Save this as lesson11-practice.py and run it with F5 in IDLE.

# Lesson 11: Drawing with Turtle
# WHAT TO DO: Turtle is a drawing tool built into Python. This program
# draws a shape with a loop: go forward, turn right, repeat. A square
# needs 4 sides, but the loop below repeats only 3 times. Fix line 18:
# change range(3) to range(4).
# HINT: Each repeat draws one side and one 90-degree turn, so 4 repeats
# make a square. Only change the number 3.
# NOTE: On a computer with no screen, Turtle cannot open its drawing
# window, so the program prints a message instead of drawing. That is
# expected there — run it in IDLE on your own computer to see the square.
# Run with F5 in IDLE. You are done when the drawing is a closed square.

import turtle

try:
    t = turtle.Turtle()
    t.color("blue")
    for side in range(3):  # <-- CHANGE THIS LINE: a square has 4 sides
        t.forward(100)
        t.right(90)
    turtle.done()
except Exception:
    print("Turtle needs a screen to draw.")
    print("In IDLE, this program draws a square: 4 sides of 100 steps.")

Key takeaways

  • Turtle is built into Python: import turtle, then t = turtle.Turtle().
  • forward() and backward() move; right() and left() turn in degrees.
  • A loop plus Turtle turns repetition into pictures you can see.
  • color() changes pen color; penup()/pendown() control whether movement draws.
  • circle(50) draws a circle of radius 50; turtle.done() keeps the window open.

Next lesson: Lists.


Quick quiz

  1. What does import turtle do, and why is it needed?
  2. What do t.forward(100) and t.right(90) do?
  3. Why is the loop version of the square better than writing all eight lines out?
  4. What do penup() and pendown() do?
  5. What does turtle.done() do, and what happens without it?

Answer key: 1. It loads the Turtle tool; without it Python does not know what turtle means. 2. Move forward 100 steps; turn right 90 degrees. 3. It says the two moves once and repeats them four times, instead of retyping them. 4. penup() lifts the pen so movement draws nothing; pendown() puts it back down to draw again. 5. It keeps the drawing window open; without it the window may close at once.