Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Part B Here is solution code for the Recipe class from last time. To simplify the code, we have removed the input checking in the
Part B
Here is solution code for the Recipe class from last time. To simplify the code, we have removed the input checking in the init method, as well
as the method.
In : class Recipe:
def self title, ingredients, directions:
self.title title
self.ingredients ingredients
self.directions directions
defrmulself multiplier:
multipliedingredients key : multiplierval for key, val in self.ingredients.items
return Recipeselftitle, multipliedingredients, self.directions
Now, implement subtraction in which the first argument is a Pantry and the second argument is a Recipe The relevant magic method for this is
called and should be implemented in the Pantry class. Here's how subtraction mypantry myrecipe should work:
You may assume that mypantry and myrecipe are valid instances of their class. In particular, all quantities of ingredients are positive numbers
int s or float s
If all keys from myrecipe. ingredients are present in mypantry, and if they all have values smaller than their values in mypantry, then the
result of mypantry myrecipe is a new Pantry object in which the values corresponding to the keys have been reduced by the quantity in
myrecipe.
If a key is present in mypantry but not in myrecipe, then it is treated as though it is present in mypantry with value
For now, you can assume that the conditions of clause are met, and that subtraction should therefore "work." That is you can assume that you have
enough of all ingredients in the pantry to make the recipe. For example, with mypantry from Part
title "cookies"
ingredients
"flour grams:
"butter grams :
"salt arams :
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