Question: class Animal: def init _ ( self , name, habitat ) : if habitat ! = type ( self ) . habitat: raise Exception (

class Animal:
def
init
_(self, name, habitat):
if habitat != type(self).habitat:
raise Exception('{0:10s} is an invalid habitat for animal {1:12s}'.format(habitat, name))
self.name = name
class Horse(Animal):
habitat = 'land'
def moves(self):
print(InThe horse named {0:10s} gallops on {1:85}'.format(self.name, self.habitat))
class Whale(Animal):
habitat = 'ocean'
def moves(self):
print(InThe whale named {0:10s} swims along {1:85}'.format(self.name, self.habitat))
class Tiger(Animal):
habitat = 'mountain'
def moves(self):
print("InThe tiger named {0:10s} roars aloft in {1:85}'.format(self.name, self.habitat))
class Eagle(Animal):
habitat = air'
def moves(self):
print('InThe eagle named {0:10s} soars aloft in {1:8}'.format(self.name, self.habitat))
class Snakel):
def _init.
(self, name, habitat):
if habitat != 'ground':
raise Exception('<0:10s} is an invalid habitat for animal {1:12s}'.format(habitat, name))
self.name = name
def moves(self):
print('InThe snake named {0:10s} slithers along' format(self.name)) What is true about the code in this question after the above definitions are executed and the following global code is executed? Check all that apply.
Ed = Horse (Mr. Ed', 'land)
Moby = Whale (Moby Dick', 'ocean')
Monty = Snake ('Python', 'ground')
Angie = Eagle (Angeline', 'air)
for m in [Ed, Moby, Monty, Angie):
m.moves()
the code contains examples of inheritance
the code contains an example of Python duck typing
the code contains examples of polymorphic behavior
each of the classes has a constructor, either inherited or as part of its definition
all classes are either Animal or subclasses of Animal
None of the listed answers is correct

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!