Sorry guys, I'm a rookie at the whole Python thing so please forgive me if the following questions are easily answered.
I'm working on my final project for class and I'm just stuck. I have no clue what's going on with this program. It isn't running properly in IDLE at all. Could someone please look it over and give me insight as to what the problems are with this program? Keep in mind I've only been dealing with Python for approximately 3 and a half months at a rate of one class a week.
##2. Ask the user to enter payroll information for the company. Set up a loop that continues to ##ask for information until they enter “DONE”. For each employee ask three questions: ##o name (first & last) ##o hours worked this week (only allow 1 through 60) ##o hourly wage (only allow 6.00 through 20.00) ##VALIDATE the hours worked and the hourly wage, and make sure a name is entered. salaries= name="Dummy" hours="0" wage="0" while name.title() !="Done": name=raw_input("Enter the first and last name of the employee: ") if name.title()=="Done": if salaries.append(name.title()): break else: while hours<1 or hours>60: hours=int(raw_input("Enter the number of hours a week worked: ")) if hours<1 or hours>60: print "Error. Please enter a number between 1 and 60: " while wage<6 or wage>20: wage=int(raw_input("Enter the hourly wage of the employee: ")) if wage<0 or wage>20: print "Error. Please enter a number between 6 and 20: " if hours <=40: grossPay=hours*wage else: grossPay=((hours-40)*(wage*1.5))+(40*wage) print name print hours print wage print grossPay ##3. Calculate each employee’s pay, and write it out to a sequential file. Be sure to include file ##I/O error handling logic. ##o Include only the weekly pay ##o Weekly pay is calculated: ## For (1-40 hours) it is hourly rate * hours worked ## For (41-60 hours) it is (hours worked – 40) * (hourly rate * 1.5) ##+ hourly rate * 40 try: salariesWage=open("PAY.txt", "w") salariesList.writelines(salaries) salariesWage.close() except(IOError): print "Error writing to file list" ##4. After all the employees are entered, read in the sequential file into a list named PAY for ##the weekly pay of each employee. Sort the list. Now print the lowest, highest, and average ##weekly pay for the week. try: employeeWage=open("PAY.txt", "r") employeeList.readlines(salaries) employeeWage.close() except(IOError): print "Error writing to file list"
Each step of what the program is supposed to do is commented out and in red.
To give a summary of what I'm having issues with:
1. The loop won't work correctly. I can loop through all three questions ONE time and that's it. When I enter a second batch of data (name, hours, wage), it only lets me input a new name then automatically assigns the previous hours and wage.
2. I can't write to a txt file properly. As of right now, I'm getting an error concerning a list not defined. Before that it was writing a PAY.txt file but it was totally blank.
3. Since I can't write to a txt file, I can't read and sort either.
Any help would be greatly appreciated.
One last thing to keep in mind is that I'm using v.2.5.4 so any new tricks in the newer versions need to be ruled out. Needs to be done in this version.
Thanks in advance.