Skip to main content

Section 3.18 Chapter Assessment

Subsection 3.18.1 Drawing with Turtles

Check your understanding

Checkpoint 3.18.1.

    What are correct ways to tell a turtle named Tex to move forward 20 pixels? Select as many as apply.
  • Tex.forward(20)
  • This is a correct way to move a turtle forward.
  • forward() + 20
  • This does not use the turtle method necessary to move a turtle forward. Additionally, how would the program know what turtle should be moving?
  • forward(20)
  • This does not use the turtle method necessary to move a turtle forward. Additionally, how would the program know what turtle should be moving?
  • forward(20).Tex
  • This is not the correct structure to execute the task.
  • Tex.forward(10 + 10)
  • You are allowed to write expressions inside of methods, so this is correctly written.

Checkpoint 3.18.2.

    Which is the correct way to make a new instance of the Turtle class?
  • turtle(Turtle)
  • When making a new instance of the turtle class, you need to use dot notation.
  • turtle.Turtle()
  • Yes, this is the correct way.
  • Turtle.turtle()
  • turtle represents the class and should be first.
  • Turtle(turtle)
  • When making a new instance of the turtle class, you need to use dot notation.

Checkpoint 3.18.3.

    What does each instance of the Turtle class represent?
  • The turtle class.
  • Though each instance does use the turtle class, this is not the best answer.
  • The same turtle that is used in each drawing your programs make.
  • Each instance that is made using the turtle class is unique. Remember how you can have multiple ’turtles’ in a single drawing? Each of those are different turtles but they are all instances of the turtle class.
  • A unique ’turtle’ that you can use to draw.
  • Yes, an instance of the turtle class represents a unique turtle. The turtle class is like a stencil or mold that can be used to make as many turtles as you would like.

Checkpoint 3.18.4.

    Select all of the following things that methods can do:
  • Change the value of an attribute.
  • Methods can change the value that is associated with an attribute.
  • Return values.
  • Methods can return values.
  • Create new attributes of an instance and set their values.
  • Attributes do not need to be pre-declared; any code can add a new attribute to an instance just by assigning a value to it.
  • Delete object instances.
  • You do not explicitly delete object instances; when there are no variables or other references to them, so that they can’t be accessed, they are automatically deleted.
  • None of the above.
  • Methods can do at least one of the above. Take another look.

Checkpoint 3.18.5.

    For an instance of a class that is assigned to the variable student, what is the proper way to refer to the title attribute/instance variable?
  • student.title()
  • This accesses the attribute but then tries to invoke it as a method, which will fail if title is not a method.
  • title.student()
  • student is the object, so it goes before the period; the attribute goes after.
  • title.student
  • student is the object, so it goes before the period; the attribute goes after.
  • student(title)
  • This would be the syntax for a function named student being called on a variable named title.
  • student.title
  • Yes, this is the correct syntax to use.

Checkpoint 3.18.6.

What is the name of jane’s attribute (not method) that is referred to in the following code?
import turtle

jane = turtle.Turtle()
jane.forward(20)
print(jane.x)
The attribute is

Checkpoint 3.18.7.

What are the names of the instances in the following code? Please put one instance per blank space and enter them in the order that the computer would read them.
      import turtle
      wn = turtle.Screen()

      jazz = turtle.Turtle()
      jazz.forward(50)
      jazz.right(90)
      pop = turtle.Turtle()
      pop.left(180)
      pop.forward(76)

Subsection 3.18.2 Drawing with Turtles

Checkpoint 3.18.8.

Write code to draw a regular pentagon (a five-sided figure with all sides the same length).

Checkpoint 3.18.9.

Write a program that uses the turtle module to draw something. It doesn’t have to be complicated, but draw something different than we have done in the past. (Hint: if you are drawing something complicated, it could get tedious to watch it draw over and over. Try setting .speed(10) for the turtle to draw fast, or .speed(0) for it to draw super fast with no animation.)

Subsection 3.18.3 Debugging & Modules

Checkpoint 3.18.10.

    Given the above screenshot of the CodeLens animation, we can say that modules (e.g random) are which of the following?
  • variables
  • modules make use of lots of functions and variables but they are not variables themselves, do you see that arrow in the image?
  • objects
  • Correct! The arrow in the screenshot tells us that a module is an object being referenced.
  • modules can be called as variables or objects
  • While we sometimes think of variables and objects in a similar fashion they aren’t the same thing and modules definitely are not both.
  • none, they are their own unique label
  • Everything in Python has to be stored somewhere on a computer, even modules. This means modules have to be types of variables or objects.

Checkpoint 3.18.11.

Consider the above screenshot of the CodeLens animation. This code is supposed to calculate the mean (average) of the 3 numbers but there is a semantic error on which line number?

Checkpoint 3.18.12.

Fill in the blanks to describe how you would fix the error seen above.
This type error can be solved by one of the variables to a(n) .
You have attempted of activities on this page.