Question: Python (Writing list items to a text file) You need to create a file of inventory_items which has the following items. Use a loop to

Python (Writing list items to a text file)

You need to create a file of inventory_items which has the following items. Use a loop to read in each value until exit is entered for the item_name. This input represents the item_name,number_sold, price_item, and cost_item.

Blue Pens

400

1.39

0.75

No. 2 Pencils

1000

0.25

0.1

Notebooks

500

6.99

3.47

For each item entered, create a string with the values separated by commas. One item is shown as an example.

Blue Pens, 400, 1.39, 0.75

Write out each item string to file named inventory_items.txt.

Read in the lines of text and split up string line into a list. Access the appropriate list elements in order to perform the following calculation for the profit: number_sold * (price_item - cost_item). Print out the name of the item and the profit with two decimal places of precision.

Sum up the profit in order to compute the total profit.

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!