Ask a question from expert

Ask now

Python module for Cat class with methods and user input simulation

6 Pages1347 Words68 Views
   

Added on  2019-10-18

About This Document

Create a Python module for Cat class with methods and user input simulation. The module should include at least 8 methods for the Cat class and a main function that accepts user input to simulate cat adoption, feeding, and more. Keep track of the total number of cats owned as num_cats. Save all console output and user input to a log.txt file.

Python module for Cat class with methods and user input simulation

   Added on 2019-10-18

BookmarkShareRelated Documents
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 your choice. The Cat class has to keep track of the total number of cats owned as num_cats. Each cat must have a name, a color, and optionally a favorite food that defaults to "Meow Mix." Each cat also has a boolean attribute variable called is_hungry which is initially True and an attribute happiness: an int that represents the cat's level of happiness (higher = happier) and starts at 1. Cats may also have as many optional parameters and variables asyou would 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 you would like; and prints a message saying that a new cat has been acquired andwhat its name is. Parameters: self name: String color: String
Python module for Cat class with methods and user input simulation_1
fav_food: String -- is "Meow Mix" if not given Etc. of your choosing(Please remove this line and document your own parameters 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 their names and colors are the same. Parameters: self other: Cat object -- the second Cat you want to use Return: Boolean -- True if the Cat objects are equal, False otherwise Usage Examples: >>> cat = Cat("Sprinkles", "white") >>> other_cat = Cat("Princess Lady", "white", "Fancy Feast") >>> cat == other_cat False """def __repr__(self): """Describe the Cat object. Return a string that lists the pairs of attribute/values for that Cat. Including: name, color, is_hungry, fav_food, age, happiness, etc. (Remember: you can add attributes for creativity's sake or to make your additional methods work.) Parameters:
Python module for Cat class with methods and user input simulation_2
self Return: info_list: String -- Start with a list of tuples where each tuple has 2 items, an attribute followed by its value. Then convert to a string and return it. Usage Examples: >>> cat = Cat("Garbage", "grey") ### It is OK if this fails after you add additional attributes to your cats. >>> cat ### Just maintain the same format for additional 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 cat object. All cats will have the same representation. Parameters: self Return: A String containing a cat emoji (of your choosing) and a newline character and the cat's name Usage Examples: >>> cat = Cat("Sprinkles", "white") >>> print(cat) =^.^= Sprinkles """def feed(self, food):
Python module for Cat class with methods and user input simulation_3

End of preview

Want to access all the pages? Upload your documents or become a member.