Chapter 5 Exercises¶
There are 3 syntax errors in the following code. Fix it to work correctly without errors.
1from turtle import *
2space = screen()
3alex = Turtle
4alex.Forward(150)
5
(ch5ex1q)
The code below is correct, but the lines are in the wrong order. Fix it so that it runs properly.
71alex = Turtle()
2alex.forward(150)
3from turtle import *
4alex.left(90)
5space = Screen()
6alex.forward(75)
7
(ch5ex2q)
The following program is missing things on lines 1, 2, and 3. Add the missing parts.
51from ??
2space = ??
3alex = ??
4alex.forward(150)
5
(ch5ex3q)
Rearrange the code so it draws a square.
111from turtle import *
2franklin = Turtle()
3space = Screen()
4franklin.left(90)
5franklin.forward(100)
6franklin.forward(100)
7franklin.left(90)
8franklin.forward(100)
9franklin.left(90)
10franklin.forward(100)
11
(ch5ex4q)
The following code has 3 syntax errors. Fix the errors so that the code runs.
71from turtle import *
2space = Screen()
3alex = turtle()
4alex.Forward(150)
5alex.turn(90)
6alex.forward(75)
7
(ch5ex5q)
Fix the 6 errors in the following code.
91from turtle import
2space = Screen
3john = turtle()
4john.Forward(100)
5john.Left(120)
6john.forward(100)
7john.left(120)
8john.Forward(100)
9
(ch5ex6q)
The following code draws two lines of a rectangle. Add code to finish drawing the rectangle.
71from turtle import *
2space = Screen()
3alex = Turtle()
4alex.forward(150)
5alex.left(90)
6alex.forward(75)
7
(ch5ex7q)
You need to fix or add 4 things so that the code runs.
81space = Screen()
2hi = Turtle()
3hi.color(red)
4hi.Forward("50")
5hi.right(90)
6hi.color("BLUE")
7hi.forward(50)
8
(ch5ex8q)
The following code is missing 3 lines that do the required set-up. Add them so that the code runs.
41alex.forward(150)
2alex.left(90)
3alex.forward(75)
4
(ch5ex9q)
Finish the code so that it draws an equilateral triangle.
51from turtle import *
2space = Screen()
3alex = Turtle()
4alex.forward(150)
5
(ch5ex10q)
Create a drawing that includes penup, pendown, and pensize.
31
2
3
(ch5ex11q)
Fix the 5 errors.
51From turtle Import *
2space = screen()
3bob = turtle
4Bob.forward("100")
5
(ch5ex12q)
Create a drawing with at least 3 colors and using at least 3 turtles.
31
2
3
(ch5ex13q)
Fix the errors.
81from turtle import *
2jack = Screen()
3jill = Turtle()
4jill.sizepen(10)
5jill.forward(10)
6jack.sizepen(15)
7jack.forward(10)
8
(ch5ex14q)
Write code below to draw a diamond shape.
31
2
3
(ch5ex15q)
Write code that spells CS in block letters (it will look more like C5).
31
2
3
(ch5ex16q)
Write code below to draw a star like this picture.
31
2
3
(ch5ex17q)
Write code to draw a “V” starting from the center with each side a different color and only turning the turtle twice and no using penup or pendown.
31
2
3
(ch5ex18q)
Write code below to draw at least one of your initials in block style.
31
2
3
(ch5ex19q)
Use 4 turtles and 4 colors to draw a big plus sign with each segment of the plus sign being a different color.
31
2
3
(ch5ex20q)