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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started