Session 1, #1: Turtles


To draw to the screen, we will use the turtle library of Python. A library is an extra chunk of code, on top of what Python already has in it, that allows us to do specific, fancier things. Some libraries are built-in to Python, and some are designed by users which you can download separately.


Challenge: What happens if you change the 45 in the left() command to 90? Try changing it and click the Run button to see what happens.

Let's look at the program line by line:

1 import turtle Directs Python to load the turtle package, so, we can use the commands in it.
2 Blank lines are ignored by Python.
3 teddy = turtle.Turtle() Creates a variable called teddy. Variables store information while our program is running. teddy keeps track of the location and the direction facing.
4 teddy.forward(100) Since teddy is a Turtle object, we can use built-in actions, like forward().
5teddy.left(45)Another built-in function of the Turtle class is left(x) which turns our turtle.
5 teddy.forward(100) We can repeat commands. Here, we use the forward() to move forward 100 steps.