In: Computer Science
in python please!
Couple of lists you need before we start baking
material_list = ['onion', 'egg', 'cucumber', 'eggplant', 'pasta', 'tomato','butter','rice','garlic','snail']
R_eggsouffle = ["egg", "milk", "butter"]
R_escargot = ["snail",'garlic','wine','butter']
R_FriedRice_v1 = ["onion", 'rice', 'egg']
We want to check if our material can make any of these recipes
Part A
The objective here is to make a function that checks
- if your ingredients can make eggsouffle, escargot, FriedRice_v1 or not
Basically, if we pass down the recipe name into a function, it should tell me whether we can make that recipe with the ingredients in material_list or not
- for example, if your function is Enough(R) - if you pass Enough("FriedRice_v1"), the result will be yes, you can make FriedRice_v1 - but if you pass Enough("escargot"), the result will be no, you don't have enough ingredients
##### code here ######
Now Let's do the same thing using dictionary
First, let's make a dictionary with all the recipes inside
##### code here ######
Now, let's solve part A using dictionary
##### code here ######
Part B
Now Chef Robinson knows the exact quantities of the ingredients he has.
- 'onion' 150g , 'egg' 200g, 'cucumber' 300g, 'eggplant' 400g, 'pasta' 300g - 'tomato' 100g ,'butter' 420g ,'rice' 500g ,'garlic' 600g, 'snail' 2000g
Make a dictionary that tells Chef Robinson how much of each ingredients he has using tuples
##### student code here ######
The code for part A is:
ingredients = {} # storing in the dictionary
ingredients["material_list"] = ['onion', 'egg', 'cucumber', 'eggplant', 'pasta', 'tomato','butter','rice','garlic','snail']
ingredients["eggsouffle"] = ["egg", "milk", "butter"]
ingredients["escargot"] = ["snail",'garlic','wine','butter']
ingredients["FriedRice_v1"] = ["onion", 'rice', 'egg']
def Enough(recipe):
if set(ingredients[recipe]).issubset(set(ingredients["material_list"])): # check if the list elements present in other list
return 'yes' # first convert the list to set and then use subset to check if True or False
return 'no'
print(Enough("FriedRice_v1"))
print(Enough("escargot"))
The sample of the code is:
The output sample of the code is:
The code for part B is:
# storing the tuple
ingredient = (('onion', '150g') , ('egg', '200g'), ('cucumber', '300g'), ('eggplant', '400g'), ('pasta', '300g'),
('tomato', '100g') , ('butter', '420g') , ('rice', '500g') , ('garlic', '600g'), ('snail', '2000g'))
quantity = dict(ingredient) # converting tuple of tuple to dictionary
# just for displaying and testing
for k, v in quantity.items(): # displaying the key value pairs
print(k + ' : ' + v)
The sample of the code is:
The output sample of the code is:
I have hidden the file name due to the guidelines. If you have any queries regarding the above code comment down. I will help you out as soon as possible.