I need to create a class Animal, inherited from the LivingThing class.
The constructor should take in 4 parameters, name, health, , food value, and an optional argument threshold.
If the last parameter threshold is not specified, the threshold of the animal object will be a random value between 0 and 4 inclusive.
This is my code:
class Animal(LivingThing):
def __init__(self, name, health, food_value, threshold):
super().__init__(name, health, threshold)
self.food_value = food_value
def get_food_value(self):
return self.food_value
I got the correct answer only when the fourth parameter exist i.e. there's threshold.
How do I modify my code such that it allows three and four parameters?
For example:
deer = Animal("deer", 15, 6)
deer.get_threshold() ( # Between 0 and 4 inclusive) should give me 2.