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
Enter the cube's edge: 4<br> The surface area is 96 square units.<br> Python
mr_godi [17]

Answer:

See the program code below.

Explanation:

def cube_SA(edge):

 edge = int(input("Enter the cube's edge: "))

 sa = edge * edge * 6

 print("The surface area is {} square units".format(sa))

cube_SA(4)

Best Regards!

5 0
3 years ago
Write a Python 3 program to read from a .csv file containing rates from power companies. Your program should determine the avera
aliya0001 [1]

Answer:

In python:

file = open("rates.csv", "r")

ratecount = 0

ratesum = 0

mylist = []

rates = file.readlines()

for nums in rates:

     num = nums.rstrip('\n')

     mylist.append(int(num))

     for i in num:

           ratesum= ratesum + int(i)

           ratecount = ratecount + 1

print("Maximum Rate: "+str(max(mylist)))

print("Minimum Rate: "+str(min(mylist)))

print("Average Rate: "+str(ratesum/ratecount))

Explanation:

This opens the csv file

file = open("rates.csv", "r")

This initializes the number of rates in the file

ratecount = 0

This initializes the sum of the rates

ratesum = 0

This initializes an empty list

mylist = []

This reads the rates into lines

rates = file.readlines()

This iterates through the rates (as a string)

for nums in rates:

This removes the newline character \n in the rates

     num = nums.rstrip('\n')

This appends the rates (as an integer) to the empty list

     mylist.append(int(num))

The following counts the rates in the file and also sum them up

<em>      for i in num: </em>

<em>            ratesum= ratesum + int(i) </em>

<em>            ratecount = ratecount + 1 </em>

This prints the maximum of the rates

print("Maximum Rate: "+str(max(mylist)))

This prints the minimum of the rates

print("Minimum Rate: "+str(min(mylist)))

This calculates and prints the average rate

print("Average Rate: "+str(ratesum/ratecount))

6 0
3 years ago
You need to trace the route that a cat 6 utp cable takes through the ceiling and walls of your building. which tool should you u
Veronika [31]

We should use Tone Generator to to trace the route that a cat 6 utp cable takes through the ceiling and walls of your building. The tone generator can be used to test the speakers and their electrical wiring, as well as to find the frequency of hearing loss and tinnitus.

A sinusoidal signal is produced by a tone generator at the selected frequency. Can be used as a learning tool for physics as well as to test audio equipment like speakers or earbuds. You may also test the frequency range of tablet speakers.

Learn more about tone generator brainly.com/question/28017740

#SPJ4

4 0
1 year ago
What is the connection between sites that allows for intersite replication called? (Points : 5) Bridgehead server
Travka [436]

Answer: Site Link

Explanation: Site link is the type connection that is created for the different sites.It helps in the connectivity in the multiple site surrounding known as inter-site and transferring the traffic created by the replication activity.

Other options are incorrect because bridgehead servers is a device to control the domain,subnet is the part of the IP network and domain is used for the identification of address .Thus, the correct option is site link.

4 0
4 years ago
Which pdu is processed when a host computer is de-encapsulating a message at the transport layer of the tcp/ip model?.
yulyashka [42]

The PDU that is processed when a host computer is de-encapsulating a message at the transport layer of the tcp/ip model is segment.

<h3>What is this PDU about?</h3>

Note that in the transport layer, a host computer is said to often de-encapsulate  what we call a segment so that they can be able to put back data to an acceptable or given format through the use of the application layer protocol that belongs to the TCP/IP model.

Therefore, The PDU that is processed when a host computer is de-encapsulating a message at the transport layer of the tcp/ip model is segment as it is the right thing to do.

Learn more about host computer from

brainly.com/question/553980

5 0
2 years ago
Other questions:
  • Which ipv6 static route would serve as a backup route to a dynamic route learned through ospf?
    12·1 answer
  • Suppose alice, with a web-based e-mail account (such as hotmail or gmail), sends a message to bob, who accesses his mail from g
    10·1 answer
  • When assembling a desktop computer you should always install the drives before the motherboard?
    9·1 answer
  • Write an if/else statement that compares the double variable pH with 7.0 and makes the following assignments to the bool variabl
    6·1 answer
  • The area of a square is stored in a double variable named area. write an expression whose value is length of the diagonal of the
    8·1 answer
  • Can someone tell me how to fix the keyboard on ipad?- its in the middle of my screen andd i dont know how to do it
    13·1 answer
  • Write a program that asks the user to provide a word, validate that it is a word, and print the word.
    6·1 answer
  • Repeated execution of a set of programming statements is called repetitive execution.
    7·1 answer
  • If your computer determines the destination address of a network packet is to a remote network.
    9·1 answer
  • Communication between a computer and a keyboard involves ______________ transmission.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!