Go to: [Link]
com/turtle
1. Run the code in the editor and see what happens!
2. Delete the code in the editor. Copy and paste the following code. This code will
draw a square!
import turtle
t = [Link]()
[Link](5)
[Link](100)
[Link](90) #this rotates turtle 90 degrees
[Link](100)
[Link](90)
[Link](100)
[Link](90)
[Link](100)
3. This code also draws a square. Try replacing the code from step 2. Make sure
that the indentation matches the indentation on this doc.
import turtle
t = [Link]()
[Link](5)
#using the “for i in range” lets you repeat what is
indented under it the number of times you say in the
parentheses after range.
for i in range(4):
[Link](100)
[Link](90)
4. Try changing the code from step 3 to draw a triangle instead of a square.
Triangles have 3 sides, and the turtle has to turn 120 degrees at each turn.
5. You can also draw circles. Try copying and pasting this code.
import turtle
t = [Link]()
[Link](5)
[Link](100, 360) #the first number is the degrees you
want to draw, and the second number is the radius of
the circle.
6. Change the code to draw a half-circle with a radius of 75. What happens if you
make the degrees negative instead of positive?
7. [Link]("blue") will change the color of what you are drawing to blue. Try
adding this line somewhere in your code to make your half-circle blue instead of
black.
8. Using what you know, try drawing a purple square with side length 40.
9. [Link]() will let you pick up your turtle and move it without drawing a line. To
put your turtle back down, use [Link](). Using what you know, try
drawing 2 circles next to each other.
10. Try copying and pasting this code and seeing what happens. I used the modulo
operator “%” to make the turtle change color based on whether the step “i” was
even or odd.
import turtle
t = [Link]()
[Link](5)
for i in range(100):
if i % 2 == 1:
[Link]("green")
if i % 2 == 0:
[Link]("orange")
[Link](i)
[Link](30)
11. Try making the spiral different colors! You could also try changing the angle in
[Link] to make a “tighter” or “looser” spiral.