1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ber [7]
3 years ago
7

Before making a dish, we want to check whether we already have the necessary ingredients in our pantry or whether we need to go

shopping. For this problem, you will implement a method needed_ingredients for the Pantry class. needed_ingredients takes a list of recipes as its argument and returns a new Pantry containing everything missing from our pantry to make all the recipes in the list. If our pantry already has all the necessary ingredients in the needed quantities, needed_ingredients returns an empty Pantry. There may be repeated recipes in the input list, and the input list may be empty. Hints: Pantry inherits the methods of its superclass, AD, so you can subtract one pantry from another. If you have an AD and need a Pantry, you can simply call the Pantry constructor on the AD.

Computers and Technology
1 answer:
Leona [35]3 years ago
6 0

Answer:

class Pantry(AD):

              def __init__(self, ingredients):

""" We initialize the Pantry class by passing the ingredients that were passed in to the initializer for the superclass AD"""

              super().__init__(ingredients)

              def needed_ingredients(self, recipes):

""" Given a list of recipes, computes which ingredients to buy, and in which quantity to be able to make all recipes. Can be implemented in 10 lines of code."""

              # define the object new_pantry to contain the ingredients needed

               new_pantry = Pantry({})

                ingredients_present = self

                # loop over the recipes in the list

                for recipe in recipes:

                        # convert ingredients of recipe from AD to Pantry

                        ingredients = Pantry(recipe.ingredients)

                        # subtract the recipe's ingredients from ingredients_present

                          ingredients_present = ingredients_present - ingredients

                        # loop over the ingredients_present for key in ingredients_present:

                       # if any ingredients's quantity < 0, add it to new_pantry

                                                           if ingredients_present[key] < 0:

# check if ingredient is present in new_pantry, add the quantity to existing quantity

                                                               if key in new_pantry:

                                            new_pantry[key] += -1*(ingredients_present[key])

else: # if ingredient is not present in new_pantry, make a new entry for the ingredient

                                               new_pantry[key] = -1*(ingredients_present[key])

ingredients_present[key] = 0      # set the quantity of the ingredient in ingredients_present to 0

Explanation:

I believe everything else is provided in the question.

Copy all the details you were provided in the question as it is and add the needed_ingredients in the Pantry class.

If you are getting any assertion error, Update the code to set the negative quantities in ingredients_present to 0

You might be interested in
When a user modifies the fonts in a message and immediately sees the effect of a font change without actually
MaRussiya [10]

Answer:

Font view

Explanation:

4 0
3 years ago
Read 2 more answers
Free point giveaway pt.10 and brainliest to first answer
g100num [7]

Answer:

3+3=6

Explanation:

Tysm!!!

8 0
3 years ago
Read 2 more answers
23. ____________ is a slide that is used as the base design theme for other slides.​
MatroZZZ [7]

Hmmmmmmmmm, <u>powerpoint</u>?

5 0
3 years ago
The basic difference between RAM and ROM memory is: Question 5 options: A) RAM is nonvolatile while ROM is volatile. B) RAM is r
schepotkina [342]

The basic difference between RAM and ROM memory is RAM is read/write while ROM Is read-only.

Explanation:

  • A ROM, non-volatile memory, does not use to store data, but RAM is volatile and requires power to store data.
  • ROM is not given usually as a specification, but RAM is typically specified when buying a computer.
  • We can write data only once in ROM. However, once it is written, we can read it any number of times. RAM is the main memory in a computer, and read from and write to it much faster than other storage types. RAM is used to store files in use on the computer.

Hence the basic difference between RAM and ROM memory is RAM is read/write while ROM Is read-only.

6 0
3 years ago
Can you determine if an external web site was likely accessed from a computer in you department a couple of seconds ago?
fredd [130]

Answer:

Yes, it can be determined if an an external web site was likely accessed from a computer in the same department a couple of seconds ago.

Explanation:

Yes. “Dig” can be used to search that website in the local DNS server. A practical example would be to insert “dig google.com” and that will give us the result of the query time for searching and finding google.com. Supposing google.com was accessed a few seconds ago, then an entry for google.com is cached in the local DNS cache and the search or query time is 0 msec. If not the query time will be large.

3 0
3 years ago
Other questions:
  • The process of __________ encourages members to accept responsibility for the outcomes of a group and for changing the style in
    8·1 answer
  • Artemisia gentileschi used directional line brilliantly in her painting judith decapitating holofernes to draw our attention to
    12·1 answer
  • Select all examples of good keyboarding technique.
    13·2 answers
  • This toolbar can be used to change the way the text in your presentation looks. Drawing
    5·2 answers
  • If the pc-doctor software is installed on a computer's hard drive, what two different ways can the program be started?
    9·1 answer
  • FINISH THE SENTENCE <br><br> buzzfeed____reddit_____
    5·1 answer
  • Which network component allows computers to communicate on a network without being connected directly to each other?
    9·1 answer
  • How do i move an sd card from 1 phone to another phone?
    13·1 answer
  • Consumers’ ability to ""time shift"" programs using DVRs and Internet video and other situations that lack simultaneity is an ex
    6·1 answer
  • H&amp;R Block's stated purpose is: to be the leading global consumer tax company bringing tax and related solutions to clients y
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!