216k views
3 votes
Write statements to define a class that includes the following. The class will not necessarily be complete – you only have to write the member functions that I ask for. You do not need to write a main function. If any member function that you write calls another member function, you must write that function also.

- Define a class, Animal, with the following data members:

type
age
height
weight
- Write a constructor function for Class which will set the type to an empty string and the age, weight and height to zero.

- Write a member function (getExpectancy) for the class that returns the life expectancy for animal. The expectancy will be the sum of the four times the age, three times the height and two times the weight. (PYTHON)

User Ginia
by
8.0k points

1 Answer

3 votes

Answer:

Step-by-step explanation:

class Animal:

def __init__(self):

self.type = ''

self.age = 0

self.height = 0

self.weight = 0

def getExpectancy(self):

return 4 * self.age + 3 * self.height + 2 * self.weight

User Karan Singh Dhir
by
7.6k points