Trusted by 2+ million users,
1000+ happy students everyday
Showing pages 1 to 3 of 6 pages
Regarding the codeWrite a Python module inhw3.pythat includes the following:class Cat:"""An object of class Cat will have a minimum of 8 methods: __init__,__eq__, __str__, __repr__, feed, and at least three methods of yourchoice.The Cat class has to keep track of the total number of cats owned asnum_cats.Each cat must have a name, a color, and optionally a favorite food thatdefaults to "Meow Mix." Each cat also has a boolean attribute variablecalled is_hungry which is initially True and an attribute happiness: anintthat represents the cat's level of happiness (higher = happier) andstartsat 1. Cats may also have as many optional parameters and variables asyouwould like."""def __init__(self, name, color, fav_food="Meow Mix"):"""Initialize a Cat object, saving as instance attributes its name, color,favorite food (defaults to "Meow Mix"), and any other attributes youwouldlike; and prints a message saying that a new cat has been acquired andwhatits name is.Parameters:selfname: Stringcolor: String
fav_food: String -- is "Meow Mix" if not givenEtc. of your choosing(Please remove this line and document yourownparameters here)age: Int -- representing age in years of the Cat ##not required, justexample"""def __eq__(self, other):"""Compares two Cats to test equality. Cats should be equal if theirnamesand colors are the same.Parameters:selfother: Cat object -- the second Cat you want to useReturn: Boolean -- True if the Cat objects are equal, False otherwiseUsage Examples:>>> cat = Cat("Sprinkles", "white")>>> other_cat = Cat("Princess Lady", "white", "Fancy Feast")>>> cat == other_catFalse"""def __repr__(self):"""Describe the Cat object. Return a string that lists the pairs ofattribute/values for that Cat. Including: name, color, is_hungry,fav_food,age, happiness, etc. (Remember: you can add attributes for creativity'ssake or to make your additional methods work.)Parameters:
selfReturn:info_list: String -- Start with a list of tuples where each tuple has 2items, an attribute followed by its value. Then convert to a string andreturn it.Usage Examples:>>> cat = Cat("Garbage", "grey") ### It is OK if this fails after youadd additional attributes to your cats.>>> cat ### Just maintain the same format foradditional attributes as well[('name', 'Garbage'), ('color', 'grey'), ('fav_food', 'Meow Mix'),('is_hungry', True), ('happiness', 1)]"""def __str__(self):"""Gives an aesthetically pleasing representation of the referenced catobject. All cats will have the same representation.Parameters:selfReturn: A String containing a cat emoji (of your choosing) and a newlinecharacter and the cat's nameUsage Examples:>>> cat = Cat("Sprinkles", "white")>>> print(cat)=^.^=Sprinkles"""def feed(self, food):
Desklib Logo
You are reading a preview
Upload your documents to download or

Become a Desklib member to get access