Question: Your task is to read the data from inventory.txt . If there are no errors when reading the data, the program should prompt the user

Your task is to read the data from inventory.txt. If there are no errors when reading the data, the program should prompt the user to provide the desired maximum ratio of unsold items on display (call it max_ratio). This value should be a floating-point number between 0 and 1. For each day-item pair, your program should calculate the ratio of unsold items on display. If this computed ratio is higher than the value in max_ratio, your program should retain the available and computed information for this day-item pair.
To extract the data from inventory.txt, your program should have a function named read_inventory_data, which takes a single parameter the name of the file containing the data. This function should return a list of dictionaries. Each dictionary should contain the keys day_of_week, item_name, unsold_kg (calculated by subtracting the purchased kilograms from the displayed kilograms), and ratio_unsold (calculated by dividing unsold_kg by the displayed kilograms), but only if the data read from inventory.txt is valid. If there are any errors while reading data from the file, this function should raise an exception. Your main program should call this function and handle any exceptions, ensuring that the application does not crash but rather prints error messages and exits gracefully (see examples of interactions below).
To determine which day-item pair would benefit most from reviewing displayed quantities, you should sort the day-item pairs with ratio_unsold values above the max_ratio threshold value. Your program should have a function sort_inventory_data that sorts the identified day-item pairs based on the their corresponding value of ratio_unsold from highest to lowest ratio_unsold value. Day-item pairs having same ratio_unsold values should be sorted first by the day of the week (Sunday being the first day and Saturday the last) and then by item in ascending alphabetical order (i.e. apples, bananas, fish, and then finally meat).

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 Databases Questions!