Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

What tax treatment applies to gains and losses on Sec. 1244 stock?

Answered: 1 week ago