Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The Pantry class is used to keep track of items in a kitchen pantry, letting users know when an item has run out. This class
The Pantry class is used to keep track of items in a kitchen pantry, letting users know when an item has run out. This class uses a dictionary to store items, where the key is a string representing the name of the item, and the value is a numerical value of the current quantity for that item. The dictionary has been initialized in the constructor for you, do not modify it. The strings returned by the class methods must match the provided examples in the docstring. All values in the dictionary must be stored as float values. Pantry items: dict stock_pantry(item: str, qty: int/float) -> str get_item(item: str, qty: int/float) -> str __repr__() -> str representation of Pantry transfer(other_pantry: Pantry, item: str) Class diagram for Pantry __repr__(self) Special methods that provide a legible string representation for instances of the Pantry class. Objects will be represented using the format return "I am a Pantry object, my current stock is " Examples: >>> sara_pantry = Pantry() >>> sara_pantry I am a Pantry object, my current stock is {} >>> sara_pantry.stock_pantry('Bread', 2) # returned string not included >>> sara_pantry.stock_pantry('Lettuce', 1.5) # returned string not included >>> sara_pantry I am a Pantry object, my current stock is {'Bread': 2.0, 'Lettuce': 1.5} stock_pantry(self, item, qty) Adds the given quantity of item to the dictionary, returning a string with the current stock using the format "Pantry Stock for : " Examples: >>> sara_pantry = Pantry() >>> sara_pantry.stock_pantry('Lettuce', 1.5) 'Pantry Stock for Lettuce: 1.5' >>> sara_pantry.stock_pantry('Lettuce', 2) 'Pantry Stock for Lettuce: 3.5' >>> sara_pantry.stock_pantry('Cookies', 3) 'Pantry Stock for Cookies: 3.0' get_item(self, item, qty) Subtracts up to the given quantity of the item from the dictionary. If the quantity is greater than the current stock, it should only use the remaining quantity, alerting the user to buy more of that item. If the item is not in the pantry, it should also let the user know. Examples: >>> sara_pantry = Pantry() >>> sara_pantry.stock_pantry('Lettuce', 1.5) 'Pantry Stock for Lettuce: 1.5' >>> sara_pantry.get_item('Lettuce', 0.5) 'You have 1.0 of Lettuce left' >>> sara_pantry.get_item('Cereal', 5) "You don't have Cereal" >>> sara_pantry.get_item('Lettuce', 1.5) 'Add Lettuce to your shopping list!' >>> sara_pantry.items {'Lettuce': 0.0} transfer(self, other_pantry, item) Moves then entire item stock from other_pantry to the original pantry. Items that have zero stock are not moved to the original Pantry. Examples: >>> sara_pantry = Pantry() >>> sara_pantry.stock_pantry('Bread', 2) 'Pantry Stock for Bread: 2.0' >>> sara_pantry.stock_pantry('Cereal', 1) 'Pantry Stock for Cereal: 1.0' >>> sara_pantry I am a Pantry object, my current stock is {'Bread': 2.0, 'Cereal': 1.0} >>> ben_pantry = Pantry() >>> ben_pantry.stock_pantry('Cereal', 2) 'Pantry Stock for Cereal: 2.0' >>> ben_pantry.stock_pantry('Noodles', 5) 'Pantry Stock for Noodles: 5.0' >>> ben_pantry I am a Pantry object, my current stock is {'Cereal': 2.0, 'Noodles': 5.0} >>> sara_pantry.transfer(ben_pantry, 'Noodles') >>> sara_pantry I am a Pantry object, my current stock is {'Bread': 2.0, 'Cereal': 1.0, 'Noodles': 5.0} >>> ben_pantry I am a Pantry object, my current stock is {'Cereal': 2.0, 'Noodles': 0.0}
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