Draw a square spiral - Python

Last edited: 24th June 2022

The code below draws a spiral. See if you can understand what the code does and write your own version. If not, copy the code and see what happens. Can you change parts of the code to create a different outcome?

import turtle
pen=turtle.Turtle()
x=10
y=10
for i in range(0,5):
    pen.forward(x)
    pen.right(90)
    pen.forward(x)
    pen.right(90)
    x=x+y
    pen.forward(x)
    pen.right(90)
    pen.forward(x)
    pen.right(90)
    x=x+y
turtle.exitonclick()

This lesson is part of the Simple Python Challenges Course

Agree
We use cookies to provide you with a better service. Continue browsing if you are happy with this. Find out more