3.1.1. Basics
turtle is some Python code you can use to draw shapes and patterns. It can be a fun introduction to working with Python so try it out!
Note
When you save your code, do not name 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.
To get started you need to import the code you need and assign it to a variable to simplify code you need to write. Practise typing out the code rather than using copy and paste. This will help you learn it better and teach you how to code with less errors.
import turtle
pen=turtle.Turtle()
Under those two lines you can start writing your commands. Start with these and see if you can work out how to finish drawing a square.
pen.forward(50)
pen.right(90)
pen.forward(50)
Note
If you get an error, check for these common mistakes:
turtle spelt incorrectly
lowercase ‘T’ for the
Turtle()functioncapital ‘T’ when referring to the
turtlecodeno brackets after the
Turtle()functionforwardspelt incorrectly
3.1.1.1. Next steps
Once you can draw a square, try adding extra commands and changing the numbers to see what happens. Can you write your name or draw something interesting?