5.9. Chapter Exercises

There are errors in the indention in the following code. Fix it to work correctly without errors.

The following code has some syntax errors. There are two errors, but each is repeated multiple times debug to the code author copy/pasting lines of code. Fix the errors so that the code runs.

Define a function hexagon that has a turtle’s name as its parameter. Your procedure should draw a hexagon (6 sides) and the turtle should end up in its original position and facing. Remember the turns required (exterior angles) for a regular shape are \(360 / numSides\). Make your sides have a length of 50.

While you are developing your procedure, you may want to change the code that says range(1, 7) to range(1, 2). That will make the program call your procedure just once, which will make it easier to debug. Once you are drawing a hexagon, change it back to range(1, 7) to see the final pattern the program is supposed to make.

Turtle programming reference sheet

Complete the body of the function colorRectangle(turtleName, width, colorValue).

It should draw a rectangle that has a width specified by the parameter and a height of 100. It should be drawn with a color specified by the parameter colorValue. The turtle should end up in its original position and facing.

Make sure to do pendown and color at the beginning of the procedure and then do penup at the end of the procedure.

There is code in the main part of the program to draw two different color rectangles. Once you get your procedure working, you can comment it out and uncomment the last 4 lines of the program to make a cool pattern.

Turtle programming reference sheet

You have attempted of activities on this page