Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Creating the Dog Class (Exercise)

00:00 So, the first exercise is literally a review exercise from the associated Python Basics course. So at the end of the course, you ended up with a Dog class that had this class attribute and a couple of instance attributes.

00:13 And your first task is just going to be to re-create this basically, but without looking. So I want you to start from scratch, open up a new file, and then build this Dog class again with the following specifications: that it should have one class attribute called .species that has the value "Canis familiaris" or "Canis familiaris", which is the Latin name for a dog.

00:34 And then each instance of the Dog class should have a .name and an .age. Also create a readable representation for a Dog instance, which means that if you print one instance of the Dog class, then it should give a nicely readable string. And finally, you should also create an instance method called .speak() that takes a sound as an argument and prints a sentence that the dog says, the specific sound that you entered. So, for example, it could look like this.

01:00 Create an instance of Dog that you’re naming philo here, and you’re passing in a name and an age. And then you should be able to print philo and get out string that says Philo is 12 years old. And you should be able to call .speak() on the philo instance and pass it a string. This, this is how dogs speak in German. So here it’s saying, "Wau". And then Philo says Wau. So that’s the Dog class you should model.

01:27 It’s the same class that you built in the Python Basics course. So it’s literally just redoing it, but we’re redoing it from scratch, and that’s still a great exercise.

01:37 So before you move on to the next lesson where I’ll also build it out, do it yourself. Start from scratch, open up a new file, and then build the Dog class and make sure that it works as expected.

01:47 See you in the next lesson.

Become a Member to join the conversation.