Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please code it Part C Implement scalar multiplication. If cookies is a recipe , then 2*cookies is a new recipe in which all the values
please code it
Part C Implement scalar multiplication. If cookies is a recipe , then 2*cookies is a new recipe in which all the values of the ingredients have been doubled. For example: title = "cookies" ingredients = { "Flour (grams)" 400, "Butter (grams)" : 200, "Salt (grams)" : 10, "Sugar (grams)" : 100 } directions = [ "In a large mixing bowl, cut the chilled butter into the flour and sugar." "Add the salt and sugar, and combine." "Roll into a log, and freeze." "Preheat the oven to 200 C.", "Cut the log of dough into thin disks and place on baking sheet." "Bake for 12 minutes, flipping after 7 minutes." ] cookies = Recipe(title, ingredients, directions) Then, doubled_cookies = 2*cookies doubled_cookies. ingredients {'Flour (grams)': 800, 'Butter (grams)': 400, 'Salt (grams)': 20, 'Sugar (grams)': 200} Hints: The required magic method is called Lrmul_(self, multiplier). Please make sure that the return value of this magic method is a new instance of class Recipe. Dictionary comprehensions provide a convenient way to make new dictionaries from old ones. Their syntax is related to list comprehensions. For example: d = {"shortbread cookie": 2, "chocolate chip cookie" : 1} {"tasty " + key : val for key, val in d. items() } : # test case -- run this code, no need to modify. title = "cookies" ingredients = { "Flour (grams)" : 400, "Butter (grams)": 200, "Salt (grams)" : 10, "Sugar (grams)" : 100 } directions = [ "In a large mixing bowl, cut the chilled butter into the flour and sugar.", "Add the salt and combine." "Roll into a log, and freeze." "Preheat the oven to 200 C.". 1 directions = [ "In a large mixing bowl, cut the chilled butter into the flour and sugar." "Add the salt and combine." "Roll into a log, and freeze." "Preheat the oven to 200 C." "Cut the log of dough into thin disks and place on baking sheet." "Bake for 12 minutes, flipping after 7 minutes." ] cookies Recipe(title, ingredients, directions) 1 1 doubled_cookies 2*cookies doubled_cookies. ingredientsStep 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