Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Coding Question - Groceries Inventory: Suppose you are given an input file of the grocery inventory containing the item name, unit price and the

Python Coding Question -

Groceries Inventory: Suppose you are given an input file of the grocery inventory containing the item name, unit price and the total in hand. Your task is to read the file, calculate the total price for each item by multiplying unit price with total in hand and then output the result in a file.

1. The program reads from an already provided input file: price_stock.in. The format of the file is as follows:

banana, 6, 0.69

apple, 10, 2.3

orange, 32, 2.1 ......

The first column is the item name, the next column is the total in hand and the last column is the unit price

2. You will perform the file open operation. And then perform the read operation with your favorite read functions and read the content of the file.

3. Once you are done reading, start processing the contents of the file using a dictionary data structure where the key would be the name of the item like: banana and the corresponding values would be the total price which will be the unit price times the total in hand.

For example: Suppose the name of the dictionary is stock_dict and one item should be like this:

banana: 4.14 where 4.14 = 6 * 0.69

4. Once you are done building your new dictionary you are going to print the new dictionary in an output file. The format of the file would be as follows

apple 23.0

banana 4.14

orange 67.2 ....

Total price: 94.34

The first column of the output file is the name of the item and the second column is the total price for that item. Since you are using a dictionary, do not worry about the order of the item in the output file. Banana can come after apple. The very last line of the file should be the total price of the all the items. That would be the summation of the second column. You can perform a summation function on the dictionary values. No fancy formatting is required.

You are expected to use dictionary, functions and file I/O operations. There should be at least 4 user_defined functions. One main(), one file_read() to read the content of the input file and one for file_write() to write the content to another file. There should be one output file and one function build_dict() to build the dictionary.

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

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions

Question

What is electric dipole explain with example

Answered: 1 week ago

Question

What is polarization? Describe it with examples.

Answered: 1 week ago

Question

Question What are the advantages of a written bonus plan?

Answered: 1 week ago