I am new to programing and am having difficulties writing a program dealing with files. The program is to read a file, calculate an employees pay and an updated YTD pay total. After calculations the program will write to a new file.
This is what I have so far:
empName = ""
prevYTD = 0.0
payRate = 0.0
hoursWorked = 0.0
recordCount = 0
def startUp():
global empFile
print "\n\n" + "PAYROLL REPORT".center(110)+"\n"
print "Employee Name".ljust(30) + "Previous YTD".ljust(18) + \
"Updated YTD".ljust(18) + "Pay Rate".ljust(13) + \
"Hours Worked".ljust(19) + "Current Pay".ljust(8)
print "-"* 109
jobInfo = open("payroll_Assignment#7.txt", "r")
def readFile():
global empName, prevYTD, payRate, hoursWorked, eof
empRec = jobInfo.readline()
if empRec == "":
eof = True
else:
empName = empRec[:25]
prevYTD = float(empRec[25:40])
payRate = float(empRec[40:55])
hoursWorked = float(empRec[55:])
eof = False
def processRecords():
global recordCount
while not eof:
recordCount +=1
printRecord()
readFile()
def printRecord():
print empName, prevYTD, payRate, hoursWorked
def closeUp():
jobInfo.close()
print "\nNumber of records in the file was",recordCount
startUp()
readFile()
processRecords()
printRecord()
closeUp()
My problem is making a new file. The program is suppose to write to a new file and I don't know how to do it. Sorry for being so clumsy with this, I'm very new to it.