Question: Task 2 : Acquire Food Task Description Create a function called acquire _ food that takes in two file names as input parameters and returns

Task 2: Acquire Food
Task Description
Create a function called acquire_food that takes in two file names as input parameters and returns a nested dictionary.
The outer dictionary uses the Codes string as its keys.
The values of the outer dictionary are inner dictionaries that contain detailed food data.
Each inner dictionary must include the following keys:
Food Name: The name of the food item (string)
Type: The category of the food (string)
Portion: The portion size in grams (integer)
Calories: The actual energy content in kilocalories (float)
Sugars: The actual amount of sugar in grams (float)
Fat: The actual fat content in grams (float)
Carbohydrates: The actual carbohydrate content in grams (float)
Protein: The actual protein content in grams (float)
Please round all float values to 4 decimal places at the final calculation.
Note that there are 5 files provided in this task:
ingredients1.csv, ingredients2.csv, food_options1.csv and food_options2.csv
Do not edit them to avoid syntax errors.
task2.py is the main file.
CSV to Dictionary
Read the two CSV files.
Write a function called acquire_food that will take in the name of the ingredients csv file and the name of the food options csv file.
This function should work on any CSV files that follows the assumptions below.
Each Ingredients CSV data file contains
the nutritional value of each ingredient (per 100g)
column data fields Ingredient, Calories (kcal), Carbohydrates (g), Sugars (g), Protein (g), Fat (g)
Each Food Options CSV data file contains
column data fields Code, Food Name, Portion (g), Main Ingredients (Top 3), Type
The column data fields can be used to help you extract the required information. Do not assume the column fields are always in the same order. You must also determine the delimiter used in a file. Note that it will never be a comma, a space, or a parenthesis, and may differ from those shown in the provided examples.
The actual nutritional values must be calculated based on the portion size and top 3 ingredients list (which represents ingredients that makes up 40%,25% and 15% of the content of the food, respectively). For example, if the portion size of M30W031 Cat Caught the Cream Puff is 75 g, the actual nutritional values will be calculated as follows: ```
Cream Cheese is the first ingredient listed (40% of food):
Actual portion of cream cheese =40/100 x 75 g =30 g
Whipped Cream is the second ingredient listed (25% of food):
Actual portion of whipped cream =25/100 x 75 g =18.75 g
White Sugar is the third ingredient listed (15% of food):
Actual portion of white sugar =15/100 x 75 g =11.25 g
Actual ingredients nutritional values
Calories =330/100 x 30+257/100 x 18.75+387/100 x 11.25=190.725 kcal
Carbohydrates =4/100 x 30+12/100 x 18.75+100/100 x 11.25=14.7 g
Sugars =3/100 x 30+10/100 x 18.75+100/100 x 11.25=14.025 g
Protein =9/100 x 30+2/100 x 18.75+0/100 x 11.25=3.075 g
Fat =34/100 x 30+22/100 x 18.75+0/100 x 11.25=14.325 g
Example 1
M30W031{'Food Name': 'Cat Caught the Cream Puff', 'Type': 'Decadent Dessert', 'Portion': 75, 'Calories': 190.725, 'Carbohydrates': 14.7, 'Sugars': 14.025, 'Protein': 3.075, 'Fat': 14.325} M30W032{'Food Name': 'Boss Cat Bomboloni', 'Type': 'Decadent Dessert', 'Portion': 100, 'Calories': 266.3, 'Carbohydrates': 48.0, 'Sugars': 17.62, 'Protein': 4.1, 'Fat': 5.9} M30W033{'Food Name': 'Actual Hummingbird Cake', 'Type': 'Healthy Treats', 'Portion': 150, 'Calories': 286.875, 'Carbohydrates': 53.8725, 'Sugars': 4.905, 'Protein': 8.8125, 'Fat': 3.1875} M30W034{'Food Name': 'Feline Financier Bar', 'Type': 'Decadent Dessert', 'Portion': 70, 'Calories': 246.75, 'Carbohydrates': 41.146, 'Sugars': 28.063, 'Protein': 1.6695, 'Fat': 8.785} M30W035{'Food Name': 'Oatmeal Ocicat Pudding', 'Type': 'Healthy Treats', 'Portion': 90, 'Calories': 339.435, 'Carbohydrates': 40.41, 'Sugars': 14.409, 'Protein': 9.495, 'Fat': 17.145} M30W036{'Food Name': 'Limau Kohlum Leche Flan', 'Type': 'Healthy Treats', 'Portion': 100, 'Calories': 158.9, 'Carbohydrates': 25.865, 'Sugars': 5.175, 'Protein': 6.72, 'Fat': 3.52}
Take note, dictionaries are unordered so there is no need to sort the dictionary. Your answer may have a different order from the example above.
There is no need to validate the function input arguments. You may assume the function will be called with the correct parameters.
You must not import any modules for Assignment 2. Please reset to scaffold if you have opened this task before 10PM Dec 9th to get the latest files.
Task 2 : Acquire Food Task Description Create a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!