Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Start code import random import math # -------- SECTION 1 class Pantry: >>> sara_pantry = Pantry() >>> sara_pantry.stock_pantry('Bread', 2) 'Pantry Stock for Bread: 2.0'

Start code import random import math # -------- SECTION 1 class Pantry: """" >>> sara_pantry = Pantry() >>> sara_pantry.stock_pantry('Bread', 2) 'Pantry Stock for Bread: 2.0' >>> sara_pantry.stock_pantry('Cookies', 6) 'Pantry Stock for Cookies: 6.0' >>> sara_pantry.stock_pantry('Chocolate', 4) 'Pantry Stock for Chocolate: 4.0' >>> sara_pantry.stock_pantry('Pasta', 3) 'Pantry Stock for Pasta: 3.0' >>> sara_pantry I am a Pantry object, my current stock is {'Bread': 2.0, 'Cookies': 6.0, 'Chocolate': 4.0, 'Pasta': 3.0} >>> sara_pantry.get_item('Pasta', 2) 'You have 1.0 of Pasta left' >>> sara_pantry.get_item('Pasta', 6) 'Add Pasta to your shopping list!' >>> sara_pantry I am a Pantry object, my current stock is {'Bread': 2.0, 'Cookies': 6.0, 'Chocolate': 4.0, 'Pasta': 0.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.stock_pantry('Cookies', 9) 'Pantry Stock for Cookies: 9.0' >>> ben_pantry.stock_pantry('Cookies', 8) 'Pantry Stock for Cookies: 17.0' >>> ben_pantry.get_item('Pasta', 2) "You don't have Pasta" >>> ben_pantry.get_item('Cookies', 2.5) 'You have 14.5 of Cookies left' >>> sara_pantry.transfer(ben_pantry, 'Cookies') >>> sara_pantry I am a Pantry object, my current stock is {'Bread': 2.0, 'Cookies': 20.5, 'Chocolate': 4.0, 'Pasta': 0.0} >>> ben_pantry.transfer(sara_pantry, 'Rice') >>> ben_pantry.transfer(sara_pantry, 'Pasta') >>> ben_pantry I am a Pantry object, my current stock is {'Cereal': 2.0, 'Noodles': 5.0, 'Cookies': 0.0} >>> ben_pantry.transfer(sara_pantry, 'Pasta') >>> ben_pantry I am a Pantry object, my current stock is {'Cereal': 2.0, 'Noodles': 5.0, 'Cookies': 0.0} >>> sara_pantry I am a Pantry object, my current stock is {'Bread': 2.0, 'Cookies': 20.5, 'Chocolate': 4.0, 'Pasta': 0.0} """

def __init__(self): self.items = {} def __repr__(self): #--- YOUR CODE STARTS HERE pass def stock_pantry(self, item, qty): #--- YOUR CODE STARTS HERE pass def get_item(self, item, qty): #--- YOUR CODE STARTS HERE pass def transfer(self, other_pantry, item): #--- YOUR CODE STARTS HERE pass

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedpython

Section 1: The Pantry class (2 pts) 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. __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: 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: 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building The Data Lakehouse

Authors: Bill Inmon ,Mary Levins ,Ranjeet Srivastava

1st Edition

1634629663, 978-1634629669

More Books

Students also viewed these Databases questions

Question

Show the properties and structure of allotropes of carbon.

Answered: 1 week ago

Question

6. Explain the strengths of a dialectical approach.

Answered: 1 week ago