The base class Pet has attributes name and age. The derived class Dog inherits attributes from the base class Pet class and includes a breed attribute. Complete the program to: Create a generic pet, and print the pet's information using print_info(). Create a Dog pet, use print_info() to print the dog's information, and add a statement to print the dog's breed attribute.

Respuesta :

Answer:

Explanation:

class Pet:

   def __init__(self):

       self.name = ''

       self.age = 0

   def print_info(self):

       print('Pet Information:')

       print('   Name:', self.name)

       print('   Age:', self.age)

class Dog(Pet):

   def __init__(self):

       Pet.__init__(self)

       self.breed = ''

def main():

   my_pet = Pet()

   my_dog = Dog()

   pet_name = input()

   pet_age = int(input())

   dog_name = input()

   dog_age = int(input())

   dog_breed = input()

   my_pet.name = pet_name

   my_pet.age = pet_age

   my_pet.print_info()

   my_dog.name = dog_name

   my_dog.age = dog_age

   my_dog.breed = dog_breed

   my_dog.print_info()

   print('   Breed:', my_dog.breed)

main()

Ver imagen adebayodeborah8

This program is an illustration of class methods.

Class methods are methods bounded to a class and not the object of the class.

The program in Python, where comments are used to explain each line is as follows:

#This creates the pet class

class Pet:

   #This creates an instance of the pet class

   def __init__(self):

       #These initialize the name and the age of the pet

       self.name = ''

       self.age = 0

       

   #This creates the print_info method

   def print_info(self):

       #These print the pet information; name and age

       print('Pet Information:')

       print('   Name:', self.name)

       print('   Age:', self.age)

#This creates the dog class

class Dog(Pet):

   #This creates an instance of the dog class

   def __init__(self):

       #This initializes the breed of the dog

       Pet.__init__(self)

       self.breed = ''

#This defines the main method

def main():

   #This creates a pet object

   my_pet = Pet()

   #This creates a dog object

   my_dog = Dog()

   #This gets input for the pet name

   pet_name = input()

   #This gets input for the pet age

   pet_age = int(input())

   #This gets input for the dog name

   dog_name = input()

   #This gets input for the dog age

   dog_age = int(input())

   #This gets input for the dog breed

   dog_breed = input()

   #This sets the pet name

   my_pet.name = pet_name

   #This sets the pet age

   my_pet.age = pet_age

   #This calls the print_info method

   my_pet.print_info()

   #This sets the dog name

   my_dog.name = dog_name

   #This sets the dog age

   my_dog.age = dog_age

   #This sets the dog breed

   my_dog.breed = dog_breed

   #This calls the print_info method

   my_dog.print_info()

   #This prints the dog breed

   print('   Breed:', my_dog.breed)

#This calls the main method

main()

Read more about similar programs at:

https://brainly.com/question/16892176