Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3.6, problem - See attached file and code. very perplexed. I think my solutions are close but just cant get my finger on it.

Python 3.6, problem - See attached file and code. very perplexed. I think my solutions are close but just cant get my finger on it. Im not certain Im splitting this correctly and program not writing to new file. ALso line 33 error message, write statement takes 1 argument and I have two ; this is happening when i add percision (.ex, .line 33....str(inventoryValue[i]),',.2f')) and probably the next line/statement as well. Please take a look and offer some suggestions/instructions to help me understand what i've done wirong and how i may correct my errors. Thanks.

FILE:

228,SEA-13189,Pepper,Florida,8 oz.,Seasoning,8.75 135,SEA-15688,Pepper,Lemon,4 oz.,Seasoning,6.25 146,SPI-23688,Curry Powder,Hot,8 oz.,Spice,9.99 135,SPI-25678,Curry Powder,Sweet,8 oz.,Spice,9.99 156,HER-32544,Mint,Spearmint,8 oz.,Herb,10.29 156,HER-34266,Basil,French,8 oz. ,Herb,10.19 266,SPI-34878,Ginger,Cracked,8 oz.,Spice,7.89 177,SEA-34982,Jerk,Chicken and Fish,4 oz.,Seasoning,5.45 245,SEA-35677,Jerk,Pork,8 oz.,Seasoning,9.85

PROBLEM:

# Instructors folder CSV file called Inventory.txt. # Read contents of file and out put a file called InventoryX.txt. # File will contain lines displaying the following: # COUNT of items, ITEM CODE, GENERAL name, SPECIFIC name, SIZE, TYPE, PRICE per. # Example of line: 228, SEA-13189, Pepper, Florida, 8 oz., Seasoning, 8.75 # Display as Florida Pepper value of inventory. # where the name will be displayed with the SPECIFIC portion followed by the # GENERAL portion of name seperated by one space and amount will appear with # two decimal digits with commas in neatly arranged (decimals alligned, columnar # display output file. In addion, write one additional line to the file which will be # TOTAL INVENTORY which is total of the value of all items. Allign all in # columns, commas as necessary, decimal places alligned.

Here's my code:

specificName = [] generalName = [] inventoryValue = []

readFile = open('Inventory.txt','r') for line in readFile.readlines(): cols = line.split(',') specificName.append(cols[3]) generalName.append(cols[2]) inventoryValue.append(int(cols[0])*float(cols[6]))

#writing results to output file InventoryX = open('Inventory.txt','w') totalInvValue = 0 for i in range(0,len(specificName)): InventoryX.write(specificName[i] + ''\ + generalName[i]+'\t'+ (str(inventoryValue[i]),',.2f')) totalInvValue+=inventoryValue[i] InventoryX.write('Total Inventory\t'+ (str(totalInvValue),',.2f'))

InventoryX.close()

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

Beginning Apache Cassandra Development

Authors: Vivek Mishra

1st Edition

1484201426, 9781484201428

More Books

Students also viewed these Databases questions

Question

Prepare a short profile of Henry words worth Longfellow?

Answered: 1 week ago

Question

What is RAM as far as telecommunication is concerned?

Answered: 1 week ago

Question

Question 1: What is reproductive system? Question 2: What is Semen?

Answered: 1 week ago

Question

Describe the sources of long term financing.

Answered: 1 week ago