Question: Please write code for these Functions. def by_origin(foods, origin): HERRE Creates a list of foods by origin. foods is unchanged. Use: V = by_origin(foods, origin)
Please write




code for these Functions.
def by_origin(foods, origin): HERRE Creates a list of foods by origin. foods is unchanged. Use: V = by_origin(foods, origin) Parameters: foods a list of Food objects (list of Food) origin - a food origin (int) Returns: origins - Food objects from foods that are of a particular origin (list of Food) assert origin in range(len (Food .ORIGIN)) # Your code here return origins def average_calories (foods): HIERI Determines the average calories in a list of foods. foods is unchanged. Use: avg = average_calories (foods) - Parameters: foods - a list of Food objects (list of Food) Returns: avg average calories in all Food objects of foods (int) # Your code here return avg def calories_by_origin(foods, origin): HELLI Determines the average calories in a list of foods. foods is unchanged. Use: a = calories_by_origin(foods, origin) Parameters: foods - a list of Food objects (list of Food) origin - the origin of the Food objects to find (int) Returns: avg - average calories for all Foods of the requested origin (int) - HERRE assert origin in range( len(Food. ORIGIN)) # Your code here return avg def food_table (foods): HELHI Prints a formatted table of foods, sorted by name. foods is unchanged. Use: food_table(foods) Parameters: foods - a list of Food objects (list of Food) Returns: None HII # Your code here return def food_search(foods, origin, max_cals, is_veg): RI Searches for foods that fit certain conditions. foods is unchanged. Use: results = food_search(foods, origin, max_cals, is_veg) = Parameters: foods - a list of Food objects (list of Food) origin the origin of the food; if -1, accept any origin (int) max_cals - the maximum calories for the food; if , accept any calories value (int) is_veg - whether the food is vegetarian or not; if False accept any food (boolean) Returns: result - a list of foods that fit the conditions (list of Food) foods parameter must be unchanged HERI assert origin in range(-1, len(Food. ORIGIN)) # Your code here return result Write and test the function by_origin in the PyDev module Write and test the function average_calories in the PyDe Write and test the function calories_by_origin in the Pyl Write and test the function food_table in the PyDev module Write and test the function food_table in the PyDev module Food_utilities.py. The resulting table should look like: Food Origin Vegetarian Calories BBQ Pork Chinese False Beef with Green Pepper Chinese False 920 251 def by_origin(foods, origin): HERRE Creates a list of foods by origin. foods is unchanged. Use: V = by_origin(foods, origin) Parameters: foods a list of Food objects (list of Food) origin - a food origin (int) Returns: origins - Food objects from foods that are of a particular origin (list of Food) assert origin in range(len (Food .ORIGIN)) # Your code here return origins def average_calories (foods): HIERI Determines the average calories in a list of foods. foods is unchanged. Use: avg = average_calories (foods) - Parameters: foods - a list of Food objects (list of Food) Returns: avg average calories in all Food objects of foods (int) # Your code here return avg def calories_by_origin(foods, origin): HELLI Determines the average calories in a list of foods. foods is unchanged. Use: a = calories_by_origin(foods, origin) Parameters: foods - a list of Food objects (list of Food) origin - the origin of the Food objects to find (int) Returns: avg - average calories for all Foods of the requested origin (int) - HERRE assert origin in range( len(Food. ORIGIN)) # Your code here return avg def food_table (foods): HELHI Prints a formatted table of foods, sorted by name. foods is unchanged. Use: food_table(foods) Parameters: foods - a list of Food objects (list of Food) Returns: None HII # Your code here return def food_search(foods, origin, max_cals, is_veg): RI Searches for foods that fit certain conditions. foods is unchanged. Use: results = food_search(foods, origin, max_cals, is_veg) = Parameters: foods - a list of Food objects (list of Food) origin the origin of the food; if -1, accept any origin (int) max_cals - the maximum calories for the food; if , accept any calories value (int) is_veg - whether the food is vegetarian or not; if False accept any food (boolean) Returns: result - a list of foods that fit the conditions (list of Food) foods parameter must be unchanged HERI assert origin in range(-1, len(Food. ORIGIN)) # Your code here return result Write and test the function by_origin in the PyDev module Write and test the function average_calories in the PyDe Write and test the function calories_by_origin in the Pyl Write and test the function food_table in the PyDev module Write and test the function food_table in the PyDev module Food_utilities.py. The resulting table should look like: Food Origin Vegetarian Calories BBQ Pork Chinese False Beef with Green Pepper Chinese False 920 251
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
