Sep 22, 2025
This lecture covers the design and implementation of a CoinCollection class in Python, focusing on managing groups of Coin objects with useful methods.
CoinCollection class models a collection of coin objects.self.coins).add_coin(coin): Adds a coin object to the collection.__str__(): Returns a string representation of all coins in the collection for easy printing.remove_coin(coin_type): Removes the first coin matching the specified type; reports if not found.total_value(): Returns the sum of all coin values as a float.find_by_type(coin_type): Returns a list of all coins matching the given type.find_rares(): Returns a list of all coins in the collection marked as rare.display_all(): Prints all coins in the collection by leveraging the __str__ method.is_empty(): Returns True if the collection has no coins, otherwise False.my_collection = CoinCollection()my_collection.add_coin(coin1)my_collection.remove_coin("Quarter")my_collection.total_value()my_collection.find_by_type("Quarter"), my_collection.find_rares()my_collection.display_all()my_collection.is_empty()CoinCollection class.add_coin).CoinCollection class.