Draw a square - Python

Last edited: 24th June 2022

Below is Python code you can use to draw a square. NOTE: When you save the file, do not call it 'turtle' or Python will try to import the script into itself and give an error because your script does not have the necessary commands.

import turtle
pen=turtle.Turtle()
pen.forward(100)
pen.right(90)
pen.forward(100)
pen.right(90)
pen.forward(100)
pen.right(90)
pen.forward(100)
pen.right(90)

NOTE: If you get an error, check for these common mistakes:

  • turtle spelt incorrectly
  • no capital 'T' for the Turtle() function
  • no brackets after the Turtle() function
  • forward spelt incorrectly

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