Question: This is spitting out duplicate data to the output text file instead of just once...the code above sends the data to an output text file

This is spitting out duplicate data to the output text file instead of just once...the code above sends the data to an output text file and the code looks like

when it should look like this:

why is it duplicating so much?
payroll.txt file looks like this...
0000 Ben Allen 7 5 5 3 6 2 0001 Adam Faurie 18 5 8 9 8 8 0002 Chris Delorenzo 7 4 8 9 5 0003 John Kerns 38 8 8 8 8 8 0004 Michael Husserl 9 3 6 3 4 0005 James Black 15 5 5 8 8 0006 Todd Lidner 20 7.0 6.5 8 8 0007 Melanie McLaird 7 4 4 6 6 6 6 0008 Tim Messelt 13 5 6.5 7 6 7 0009 Mary Allen 25 8 8 7.5 7 4 0010 Kay Simpson 30 8 8 8 8 8
2 f open("C:\\Users Desktop Wpayroll.txt "r") 3 outfile open 'C:WUsersWusertMVDesktopWoutput. txt w 4 output 6 or line in f.readlines. columns-line split() id columns [01 name-columns[1 columns[2] float columns [31) 10 Wage days-columns [A:] 11 12 totalhours 0 13 14 for hour in days total hours-total Ours float hour) 1h 15 average Hours totalhours/len (days) 16 17 totalPay totalhours wage 18 result-name. LD +id+' worked '+str(totalhours) hourly pay +str (wage)+' hours: str(averagellours) '/day Total Pay: str (totalpay) 19 20 print (result) 21 output, append(result ') 22 outfile ,write (output str 'Vn') 23 24 25 26 out file close() 27 28 29
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
