Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

More Books

Students also viewed these Databases questions