5.11. Chapter Assessment - Turtle and Object Mechanics¶
Check your understanding
- 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.
What are correct ways to tell a turtle named Tex to move forward 20 pixels? Select as many as apply.
- turtle(Turtle)
- When making a new instace 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 instace of the turtle class, you need to use dot notation.
Which is the correct way to make a new instance of the Turtle class?
- 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.
What does each instance of the Turtle class represent?
- 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.
Select all of the following things that methods can do:
- 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.
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?
5.12. Chapter Assessment - Drawing with Turtle¶
Write code to draw a regular pentagon (a five-sided figure with all sides the same length).
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.)