Question: Python Question 5: (25 points) Write a function that reads from a file named inventory.txt a list of transactions on certain items and returns a

Python Python Question 5: (25 points) Write a function that reads from a

Question 5: (25 points) Write a function that reads from a file named "inventory.txt" a list of transactions on certain items and returns a dictionary representing the resulting inventory. The file "inventory.txt" contains lines describing purchases or sales of items and their amount. For example: apples + 20 oranges + 10 apples - 5 oranges + 5 pears + 7 In this case, the resulting inventory is 15 apples, 15 oranges, and 7 pears. Therefore, your function must return the following dictionary: {"apples":15, "oranges":15, "pears":7} If the amount of an item drops down to e, then you shouldn't report it in the dictionary. So, only items with POSITIVE Inventory amounts should be reported. The file may contain many different items, the only transaction symbols are and "-", and the amounts are always integers. You can also assume that you will never sell more than you have in the inventory. So, the inventory can never be negative for any items. det inventory eturn

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!