Question: Part B: Inheritance ( 1 0 Pts ) Instructions: ( pets . py ) In this part, you will write 2 classes ( Dog and
Part B: Inheritance Pts
Instructions: petspy
In this part, you will write classes Dog and Panda that inherit all the functionalities from the Animal class and add some more.
Task : Dog Class
It represents a dog entity with specific attributes and behavior. It is a subclass of class Animal that should include the following additional attributes and methods:
Attributes:
In addition to the attributes inherited from the Animal class iex y id and species the Class should have the following attributes:
name: The dogs name. Default is "Dogzilla".
gender: The dogs gender. Default is "Female".
Methods:
init method: Accepts six arguments: self, name default "Dogzilla" gender default "Female" x default y default id default in this order. It uses the constructor for class Animal to store species Dog x y andid as data attributes. Hint: check out how MassParticle calls the Particle init in Code Listing
# Example usage:
animal DogDogzilla "Female",
printanimal # Animal Dog ID: is at
about method: Accepts one argument: self. It Returns a string introducing the dog, including its name and position. Additionally, it identifies the dog as a race watcher.
# Example usage:
animal Dog
animal.about
Hi my name is Dogzilla.
Animal Dog ID: is at
Im your female dog race watcher.
Task : Panda Class
representing a panda entity where you should be able to decide on the namegender of your Panda. You can also interact with it by feeding your Panda, playing with your Panda, and talking to your Panda. It is a subclass of class Animal that should include the following additional attributes and methods:
Attributes:
In addition to the attributes inherited from the Animal class iex y id and species the Class should have the following attributes:
name: The pandas name.
gender: The pandas gender.
furcolor: The pandas fur color.
As well as some other attributes that are related to physicalmental health status:
hunger
thirst
loneliness
Methods:
init method: Accepts seven arguments: x default y default id default name default "Fluffy" gender default "Unknown" and furcolor default "Red"
It uses the constructor for class Animal to store species Panda x y andid as data attributes.
When a Panda object is created, hisher initial status have a hunger and thirst level of Their loneliness is at
Once all attributes are initialized, a message is printed from the animals TALKS dictionary with a newborn message TALKSnewborn
# Example usage:
animal Panda "Fluffy", "male", "Red"
# Hi master, my name is Fluffy.
printanimal
# Animal Panda ID: is at
status method: prints a string representation of the Pandas status.
# Example usage:
animal Panda "Fluffy", "male", "Red"
animal.status
Panda Fluffy ID: Gender: male, Fur Color: "Red"
Position:
Hunger: Thirst: Loneliness:
replytomaster method: accepts as argument event. It prints a reply to the master based on the Pandas mood and status such as hunger, thirst, and loneliness.
event is a key that determines which specific message from the animals TALKS dictionary to use for its initial reply. It first prints the animals name followed by the message tied to the given event.
Then, it evaluates the animals attributes:
Hunger hunger and Thirst thirst: If both exceeds or equal the animal replies with a tired message TALKStired
Hunger hunger: If greater than or equal to the animal replies with a hunger messages TALKShunger
Thirst thirst: If greater than or equal to the animal replies with a thirsty messages TALKSthirsty
Loneliness loneliness: If greater than or equal to the animal replies with a loneliness message TALKSloneliness
If none of the above conditions are met, the animal replies with a default message TALKSdefault
# Example usage:
animal Panda "Fluffy", "male", "Red"
animal.replytomasterplay
Fluffy: Happy to have your company ~
Fluffy: Could you stay with me for a little while
animal.hunger
animal.replytomasterfeed
Fluffy: Yummy
Fluffy: Im too hungry or thirsty to talk right now...
play method: This method does not take any parameter. It will update the loneliness attribute. It Reduces loneliness by but increases hunger and thirst slightly by It ensures that loneliness does not go below and that hunger and thirst does not go above
It will then call the replytomaster method with the 'play' event.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
