← Python

Drawing with a turtle

Predict, run and change short Python programs that draw shapes.

A turtle walks across the screen, leaving a line behind. Your program tells it where to go.

PredictRead the code and say what it will do before you run anything.

Predict

square.py
from turtle import *

forward(100)
right(90)
forward(100)
right(90)
forward(100)
right(90)
forward(100)
right(90)

Read the code. What shape will the turtle draw? Where will it finish?

Reveal what happens
Predict
RunRun it and compare the result with your prediction.

Run

Run the program and compare it with your prediction.

square.py
from turtle import *

forward(100)
right(90)
forward(100)
right(90)
forward(100)
right(90)
forward(100)
right(90)
Try it yourselfYour edits are saved in this browser.
InvestigateTrace how each line of code connects to what you see.

Investigate

The same square, in fewer lines. Which part repeats? What does range(4) control?

square.py
from turtle import *

for i in range(4):
    forward(100)
    right(90)
Investigate
ModifyChange the code on purpose and check the result.

Modify

Change the loop to draw a triangle. Hint: the turtle turns by an exterior angle.

Try it yourselfYour edits are saved in this browser.
MakeBuild something new using what you have learned.

Make

Design your own shape or pattern. Try color-style commands such as pencolor("red").

Try it yourselfYour edits are saved in this browser.