I'm trying to figure out why the output to the console and the output to the output.txt file only displays one line of the database entries from my original text file when there are ten lines. It works correctly for that single line and the math is right but I need the output to display all the data at once. Any suggestions?
f = open("C:\\Users\\myname\\Desktop\\payroll.txt", "r")
output=[]
for line in f.readlines():
columns=line.split()
id=columns[0]
name=columns[1] + ' ' + columns[2]
wage=float(columns[3])
days=columns[4:]
totalhours=0
for hour in days:
totalhours=totalhours + float(hour)
averageHours=totalhours/len(days)
totalPay=totalhours*wage
result=name+' ID'+id+' worked '+str(totalhours)+' hourly pay $'+str(wage)+' hours: ' + str(averageHours) + '/day Total Pay: $' + str(totalPay)
print(result)
output.append(result+'\n')
outfile=open('C:\\Users\\myname\\Desktop\\output.txt','w')
outfile.writelines(output)
outfile.close()