Adding Coat Color (Exercise)
00:00
Well, let’s get started with the first actual exercise where you do something new. In this exercise, your task is to modify the Dog
class to include a third instance attribute called .coat_color
, which stores the color of the dog’s coat as a string.
00:14 You should store the new class in the file and test it out by adding the following code at the bottom of that file. Again, we’re going to work with Philo, whose name I can’t pronounce, but that’s okay.
00:25
It’s going to be a Dog
instance with the name "Philo"
, 5
years old. Whoops, I made it too old. And a brown .coat_color
. And then we’re going to print that out.
00:34
And here it’s using just an f-string to print out the name of the dog and its coat color, so the output should look like this: Philo's coat is brown.
So this is the task.
00:48
It seems like it’s just about adding a third instance attribute and then printing it out. Maybe we’re going to also do something with the .__str__()
method to include the coat color into the print()
output—a little stretch goal that you could do if you want to, but it looks like you don’t even have to.
01:02 It’s just about adding the instance attribute and then being able to interact with it. Let’s try this out, and then see you in the next lesson, where I will try it out myself.
Become a Member to join the conversation.