Question
I have this template in Python, where the main function has to stay the way it is.After implementing a Character class and its methods correctly,
I have this template in Python, where the main function has to stay the way it is.After implementing a Character class and its methods correctly, running the given main should produce the following output. Note, that the same output has been expressed in two ways in the example below. The left column shows what the output actually looks like and the right column is there just to emphasize how the space characters should appear in the output. The program should only output what is shown on the left column.
The actual job is to implement the methods that main uses for the Character class. The implementation should be such that the given main's output with the class implementation looks like the example above.
Even though the constructor method __init__ only has one parameter, the items the character is carrying still need to be stored in some attribute.
Another important detail is that the printout method prints the items in an alphabetical order. In addition, if the character has no items, printout should display:
class Character: # TODO: the class implementation goes here. def main(): character1 = Character("Conan the Barbarian") character2 = Character("Deadpool") for test_item in ["sword", "sausage", "plate armor", "sausage", "sausage"]: character1.give_item(test_item) for test_item in ["gun", "sword", "gun", "sword", "hero outfit"]: character2.give_item(test_item) character1.remove_item("sausage") character2.remove_item("hero outfit") character1.printout() character2.printout() for hero in [character1, character2]: print(f"{hero.get_name()}:") for test_item in ["sausage", "sword", "plate armor", "gun", "hero outfit"]: if hero.has_item(test_item): print(f" {test_item}: {hero.how_many(test_item)} found.") else: print(f" {test_item}: none found.") if __name__ == "__main__": main()Name: Conan the Barbarian 1 plate armor 2 sausage 1 sword Name: Deadpool 2 gun 2 sword Conan the Barbarian: sausage: 2 found. sword: 1 found. plate armor: 1 found. gun: none found. hero outfit: none found. Deadpool: sausage: none found. sword: 2 found. plate armor: none found. gun: 2 found. hero outfit: none found. Name: Tanktop u Vegetarian us nothing
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