Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Class Animal (object): population = 0 def_init_self, name); self.name = name def

ID: 3815447 • Letter: C

Question

Class Animal (object): population = 0 def_init_self, name); self.name = name def_str_(self); return "I am an instances of (). My name is (). ".format (self._____class______, self.name) def___repr____(self); return self.______str____() def make_sound (self); return*() is trying to speak but its method doesn't do much". format (self.name) class Dog (Animal); def_init_(self, name, breed); super () .____init_______(name) self.breed = breed def_____str____(self); print (super () _____str_______ ()) return My breed is ()". format (self.breed) def make_sound(self): return [] says woof!". format (self.name) class Cat (Animal); Pass animals = {'Felix': ('cat', None), 'Fido': ('Dog', 'mutt'), 'Charlie': ('Dog', 'spaniel')} animals_list = [] for k in animals; if animalst [k] [1]; animals_list .append (globals () [animals [k] [0]] (k, animals [k] [1])) else: animals_list .append (globals() [animals [k] [0]] [k]) Animal.population + = 1 for animal in animals_list: print(animal) print(animal.make_sound()) print("Animal population is ()". format (Animals.population)) (a) What output will the program produce? Explain the result. (b) What is the significance of the use of globals () in the program? (c) What is the significance of the use of super () in the program? (d) The Cat class appears to do nothing. Explain how a Cat instance would be created.

Explanation / Answer

a) output produced is as mentioned below

Since, 'Cat' class does not provide any implementation for the base class animal other than name and its class, hence when print(animal()) is called __str__(self) function of Animal class gets called and when animal.makesound() get called for Cat object, makesound() function of Animal class gets called.

For, 'Dog' class __str__(self) function of Dog class gets called and inturn it calls __str__(self) function of Animal class hence results in two sentences, one from Animal class and other from Derived class.

b) globals() signifies that the instance of animals which are going to be used is the global one and not the local one in case there would have one.

c) super() denotes the immediate parent class of any class.

d) cat has derived from Animal base class and inherits all the functionalities of Animal class until unless cat class provides its own functionalities.

Here, pass keyword is used to specify that cat class is not providing its own functionalities rather cat class uses the functionalities provided by Animal class. When cat class is instantiated constructor __init__() of Animal class would be called and the name of the Cat would be initialized to 'Felix'.