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 : Acquire Food
Task Description
Create a function called acquirefood 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 decimal places at the final calculation.
Note that there are files provided in this task:
ingredientscsv ingredientscsv foodoptionscsv and foodoptionscsv
Do not edit them to avoid syntax errors.
taskpy is the main file.
CSV to Dictionary
Read the two CSV files.
Write a function called acquirefood 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 g
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 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 ingredients list which represents ingredients that makes up and of the content of the food, respectively For example, if the portion size of MW Cat Caught the Cream Puff is g the actual nutritional values will be calculated as follows:
Cream Cheese is the first ingredient listed of food:
Actual portion of cream cheese x g g
Whipped Cream is the second ingredient listed of food:
Actual portion of whipped cream x g g
White Sugar is the third ingredient listed of food:
Actual portion of white sugar x g g
Actual ingredients nutritional values
Calories x x x kcal
Carbohydrates x x x g
Sugars x x x g
Protein x x x g
Fat x x x g
Example
MWFood Name': 'Cat Caught the Cream Puff', 'Type': 'Decadent Dessert', 'Portion': 'Calories': 'Carbohydrates': 'Sugars': 'Protein': 'Fat': MWFood Name': 'Boss Cat Bomboloni', 'Type': 'Decadent Dessert', 'Portion': 'Calories': 'Carbohydrates': 'Sugars': 'Protein': 'Fat': MWFood Name': 'Actual Hummingbird Cake', 'Type': 'Healthy Treats', 'Portion': 'Calories': 'Carbohydrates': 'Sugars': 'Protein': 'Fat': MWFood Name': 'Feline Financier Bar', 'Type': 'Decadent Dessert', 'Portion': 'Calories': 'Carbohydrates': 'Sugars': 'Protein': 'Fat': MWFood Name': 'Oatmeal Ocicat Pudding', 'Type': 'Healthy Treats', 'Portion': 'Calories': 'Carbohydrates': 'Sugars': 'Protein': 'Fat': MWFood Name': 'Limau Kohlum Leche Flan', 'Type': 'Healthy Treats', 'Portion': 'Calories': 'Carbohydrates': 'Sugars': 'Protein': 'Fat':
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 Please reset to scaffold if you have opened this task before PM Dec th to get the latest files.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
