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. I can not get the program to do the calculations or make, write, or save the updated file.
This is what I have so far:
empName = ""
prevYTD = 0.0
payRate = 0.0
hoursWorked = 0.0
updatedYTD = 0.0
currentPay = 0.0
eof = False
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
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 calcPay():
global prevYTD, updatedYTD, payRate, hoursWorked, currentPay, eof
currentPay == payRate*hoursWorked
updatedYTD == currentPay+prevYTD
def printRecord():
print empName, prevYTD,updatedYTD, payRate, hoursWorked, currentPay
def closeUp():
jobInfo.close()
print "\nNumber of records in the file was",recordCount
jobInfo = open("payroll_Assignment#7.txt","r")
jobInfo = open("payroll_Assignment#7.txt","w")
startUp()
readFile()
processRecords()
calcPay()
printRecord()
closeUp()