Skip to main content

Section 17.7 Practice - Write a Procedure

Time for a little practice - try writing your own procedure. There is an answer available, but don’t look at it until you have tried writing the procedure on your own!

Checkpoint 17.7.2.

Write a procedure pentagon that takes two parameters: the turtle to draw with and the length to make each side. (A pentagon has five sides and five corners - each turn will need to be 72 degrees).
Answer.
# DEFINE THE PROCEDURE
def pentagon(turtle, size):
    turtle.forward(size)
    turtle.right(72)
    turtle.forward(size)
    turtle.right(72)
    turtle.forward(size)
    turtle.right(72)
    turtle.forward(size)
    turtle.right(72)
    turtle.forward(size)
    turtle.right(72)
You have attempted of activities on this page.