Question
**PYTHON** In this question, create a class called animal that has two member variables: species and name that are both string variables. The animal class
**PYTHON**
In this question, create a class called animal that has two member variables: species and name that are both string variables. The animal class will support two functions: get_name and get_species that both return their respective member variables. In addition, override the __str__ function to return a string formatted as such: "name is a species". For example, if an animal instance had the properties Murray for name and Cat for species, the __str__ when called would return Murray is a cat.
class Animal(object): ''' Represents an Animal Attributes ---------- name: A string representing the animal object's name species: A string designating the animal object's species Methods ------- __init__: Initializes the Animal object. get_name: returns name attribute of Animal object get_species: returns species attribute of Animal object __str__: returns a string representation of the Animal object ''' def __init__(self, species, name): ''' Initializes the Animal class. Parameters ---------------- species: A string representing the animal object's species name: A string representing the animal object's name Attributes ---------- Animal.species (str): set to `species`. Animal.name (str): set to `name`. ''' # YOUR CODE HERE def get_name(self): ''' Retrieves the name attribute of the Animal object.
Returns ------- String. name attribute. ''' # YOUR CODE HERE def get_species(self): ''' Retrieves the species attribute of the Animal object.
Returns ------- String. species attribute. ''' # YOUR CODE HERE def __str__(self): ''' Returns string representation of the Animal object
Returns ------- String. name + " is a " + species ''' # YOUR CODE HERE
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