Question: 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

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!