Question: Language: Python Topic: Files I/O assume that the .txt file will be formatted as follows: food name calories food_type $price food name calories food_type $price
Language: Python
Topic: Files I/O
assume that the .txt file will be formatted as follows:
food name calories food_type $price
food name calories food_type $price ...
There will be a line with the name of the food item followed by a line with the amount of calories, the type of food, and the price. The file may contain a variable number of empty lines between each food item
An example file could be formatted as follows:
Chicken Parm 710 Entree $17.50
gelato 100 dessert $4.00
Function name : hangry Parameters : file (str), num (int), food_type (str) Returns: list Description : Its 6 pm, and youre sitting in recitation just thinking about eating dinner. Youre getting really hangry, so you start looking up food online. Write a function that takes in a .txt file name which is in the format shown above. The function should use the file to find num food items of food_type with the most calories and return them in a list in order of most to least calories. If there are multiple foods with the same number of calories, choose the foods which come first in the file. If there are less than num foods of that food type, return a list with how many ever foods there are of that food type in order of most to least calories. This function should not make any changes to the txt file.
Test Cases:
>>> hangry('olive_garden.txt', 4, 'app') ['dip duo', 'Lasagna dip', 'calamari','spicy alfredo chicken'] >>> hangry('olive_garden.txt', 2, 'noodles') [] Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
