Question: Python 3.7.3 ***Add to class Animal methods setAge() and getAge() to set and retrieve the age of the Animal object. Modify the existing methods accordingly.

Python 3.7.3

***Add to class Animal methods setAge() and getAge() to set and retrieve the age of the Animal object. Modify the existing methods accordingly. Sample output below.

Note that the methods speak() and __repr__() alone need to be edited/included.

>>> flipper = Animal('dolphin', 'whistle', 2)

>>> flipper.getAge()

2

>>> flipper.getSpecies()

'dolphin'

>>> flipper.speak()

'I am a dolphin of age 2 and I whistle.'

>>> flipper

Animal(dolphin, 2, whistle)

>>> print(flipper)

I am a dolphin of age 2 and I whistle.

>>> winter = Animal()

>>> winter.setLanguage('whistle')

>>> winter.setAge(4)

>>> winter.setSpecies('dolphin')

>>> winter

Animal(dolphin, 4, whistle)

>>> print(winter)

I am a dolphin of age 4 and I whistle

>>>

class Animal(object): 'a class that abstracts an animal' def __init__(self, s = 'default', l = 'default', a = 'default'): self.species = s self.language = l self.age = a def setSpecies(self, name): 'sets the species of the animal' self.species = name

def getSpecies(self): 'get animal species' return self.species def setLanguage(self, lang): 'sets the language of the animal' self.language = lang

def setAge(self, age):

def getAge(self): def speak(self): def __repr__(self):

def __str__(self): return self.speak()

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 Databases Questions!