# Chapter 10 Exercises¶

1. Fix 4 syntax errors in the code below to correctly draw a square

Add a * at the end of line 1. Change screen to Screen in line 2. Add () at the end of line 3. Change line 5 to [1,2,3,4].

2. The code currently draws a square. Change it so that it draws a triangle.

Change the list to only have 3 items in it and change the angle to be 120.

3. Fix the code below to draw a rectangle. You will need to fix the indention on 3 lines.

Change the indention on lines 2, 9 and 10 as shown below.

4. Fix the errors in the code so that it draws an octagon.

It should be range(8) and add a colon afterwards. Fix the indentation on the last line to be in the for loop, and switch the two numbers in the forward and right methods.

5. Fill in values for x on line 5 and y on line 7 to allow the code below to correctly draw a pentagon.

Change x to 5 and y to 72.

6. Complete the code on lines 5 and 7 to draw a hexagon.

Line 5 needs to say “for sides in range(6)” and line 7 has to have the turtle turning right by 60.

7. Finish the code on lines 1, 2, 3, 6 and 8 below to correctly draw a triangle.

Add turtle import * to the end of line 1. Add Screen() to the end of line 2. Add Turtle() at the end of line 3. Set line 6 to repeat 3 times. Set line 8 to turn left 120 degrees.

8. Finish the code to draw a 15 sided figure with each side having a length of 40.

You need a for loop that iterates through 15 elements. In the body of the loop, the turtle must go forward 40 and turn left 24.

9. Fix the indention in the code below to correctly draw 20 pentagons.

Indent lines 13-15 as shown below.

10. The procedure below draws a square. Write code that uses the procedure to draw two squares connected by a line 50 units in length.

Call the statements needed to create a turtle. Then call the function, turn it left, move it forward, and call the function again

11. Fix the following code below to draw a circle of turtles using the stamp procedure. You will need to change 3 lines.

On line 5 add penup(). On line 6 change it to (10). On line 9 change it to (-50).

12. Complete the code where the x's are so that the code draws 20 triangles.

You need to call the Turtle() and then set the range to 20, then the next range to 3 and make the turtle go foward 60 and right 120.

13. Rewrite the following code to create a procedure to draw a square with a turtle. Pass the turtle and the size of the square as input (parameters) to the procedure.

Define the procedure as shown below. Create a turtle and do all set-up before calling the procedure.

14. Currently, the code has a turtle drawing a straight line. Add 2 lines of code (1 before the loop and 1 in the loop) to make the turtle stamp in the line.

You have to add a penup statement before the loop and a stamp statement in the loop.

15. Rewrite the following code to create a procedure to draw a rectangle with a turtle. Pass the turtle and the length and width of the rectangle as parameters to the procedure.

Define the procedure to draw a rectangle given a turtle, the length, and the width. Call the procedure to test it.

16. Complete the code so that the turtle stamps a square pattern 20 times (it should look like a circle enclosing a couple of circles if you use a turn angle of 18)

Make sure to use penup before the loop. Inside the loop, there should be another loop, and you should call the stamp method inside both loops.

17. Create a procedure to draw 4 turtles at the 4 corners of a square using the stamp procedure.

Define the procedure as shown below.

18. Create a procedure that takes in a turtle and integer parameter. The procedure should stamp a turtle shape into a circle in 20 steps with the forward number being equal to the parameter.

In the procedure, have the two parameters. Change the turtle shape to “turtle” and use penup. Then have a loop for range of 20. Inside the loop make the turtle go forward by the int parameter value. Use the stamp method and then the turn right by 18.