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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started