Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Challenge 7

This challenge is intended to be taken after the classes section.

Problem 1: The Dog Class

  • Create a class called Dog.
  • The __init__ method should take name and breed as arguments.
  • Create an instance method called bark that prints "Woof!".
  • Create an instance of your Dog class and call the bark method.

Problem 2: The Car Class

  • Create a class called Car.
  • The __init__ method should take make, model, and year.
  • Use the @property decorator to create a description property that returns a string like "2023 Honda Civic".
  • Create an instance of the Car and print its description.

Problem 3: Inheritance

  • Create a Person class with name and age attributes.
  • Create a Student class that inherits from Person.
  • The Student class should have an additional student_id attribute.
  • Create an instance of Student and print out their name, age, and student ID.


Contributors: