Functions with Turtles
Let's use functions to simply our turtle drawing programs.
import turtle
def square():
for a in range(4):
turtle.forward(50)
turtle.left(90)
square()
turtle.forward(100)
square()
Here we created a square function that draws a square. We can run this function as many times as we like using the square() command.
Challenge 1. Family of shapes
In the trinket below, write a program that contains the following functions...
- square
- triangle
- pentagon
- hexagon
The first one has already been done for you.
import turtle
def square():
for a in range(4):
turtle.forward(50)
turtle.left(90)
square()