Question: Python Coding Question Groceries Inventorv: Suppose you are given an input file of the grocery inventory containing the item name, unit price and the total
Python Coding Question
Groceries Inventorv: 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. Lab Scenario: 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 You will perform the file open operation. And then perform the read operation with your 2. favorite read functions and read the content of the file 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: 3. "banana": 4.14 where 4.14-6 * 0.69 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 4. 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 5. Please don't forget to close the file 6. For this lab, you are expected to use dictionary, functions and file /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(0 to write the content to another file. The output file should be named as: firstname lastname ILA9.out and one function build dict) to build the dictionary Groceries Inventorv: 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. Lab Scenario: 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 You will perform the file open operation. And then perform the read operation with your 2. favorite read functions and read the content of the file 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: 3. "banana": 4.14 where 4.14-6 * 0.69 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 4. 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 5. Please don't forget to close the file 6. For this lab, you are expected to use dictionary, functions and file /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(0 to write the content to another file. The output file should be named as: firstname lastname ILA9.out and one function build dict) to build the dictionary
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
