Back to Python Mastery
BeginnerChildren
Fun with Python Turtle
Let's have some fun by drawing with code! Python has a special feature called the 'turtle' module that lets you draw cool pictures.
Imagine a tiny turtle with a pen tied to its tail. You can tell the turtle where to go, and it will draw a line as it moves.
First, we need to tell Python that we want to use the turtle. We do this by 'importing' it:
Now we have our turtle! Let's tell it to move forward:
This tells the turtle to move 100 steps forward. How about turning?
This tells the turtle to turn right by 90 degrees (a perfect corner).
If we combine these commands, we can draw a square:
Try it out in the exercise below!
Imagine a tiny turtle with a pen tied to its tail. You can tell the turtle where to go, and it will draw a line as it moves.
First, we need to tell Python that we want to use the turtle. We do this by 'importing' it:
import turtleNow we have our turtle! Let's tell it to move forward:
turtle.forward(100)This tells the turtle to move 100 steps forward. How about turning?
turtle.right(90)This tells the turtle to turn right by 90 degrees (a perfect corner).
If we combine these commands, we can draw a square:
turtle.forward(100)turtle.right(90)turtle.forward(100)turtle.right(90)turtle.forward(100)turtle.right(90)turtle.forward(100)Try it out in the exercise below!
Draw a Square
Complete the loop to make the turtle draw a square.