Question: Hello! I need to get my program to read a certain text file and i don't really understand how to do that... i've coded according

Hello! I need to get my program to read a certain text file and i don't really understand how to do that... i've coded according to my book, is there anything I can do? This code is so long that I'm havin difficulties pinpointing weaknesses, i'm using python

the file's name is empwages.txt

here's a photo of the empwages.txt

Hello! I need to get my program to read a certain text

Here is my code... theres somethin off because it keeps printing nothing sometimes:

employeenames = [] hourly_wage = [] total_hourly_worked_week = []

def menu(): print("Menu of Choices")

choice = input(""" r: Read Employees data p: Print Employee Payroll d: Display an Employee by name h: Find highest paid Employee l: Find lowest paid Employee q: Quit Please enter your Choice: """)

if choice == "r": return 'r' elif choice == "p": return 'p' elif choice == "d": return 'd' elif choice == "h": return 'h' elif choice == "l": return 'l' elif choice == "q": return 'q' else: print("You must select from the written values above.") print("Please try again") menu() def main(): choice = menu() if choice == "r": filename = input("Enter the file name please: ") get_emp_data(filename) elif choice == "p": diplay_payroll() elif choice == "d": employeeNames = input("Enter employee's name") display_by_name(employeeNames) elif choice == "h": get_high_low_paid_emp(choice) elif choice == "l": get_high_low_paid_emp(choice) elif choice == "q":

exit() else: print("Please chose from the listen values") print("Please try again") return menu()

def main(): outfile = open("empwages.txt", "w") outfile.close()

main() def get_emp_data(filename): try: inFile = open(filename, "r") for line in inFile: totalHours = 0 payroll = line.split() employeenames.append(payroll[0]) hourly_wage.append(float(payroll[1]))

for i in range(2,7): totalHours = totalHours + float(payroll[i]) total_hourly_worked_week.append(totalHours) print("File has been read...")

except IOError: print ("Error reading file: ",filename) #Phase 2 def display_payroll(): if not employeenames: print("Employee data had not been read") print("Please read the file before making this choice")

else: totalPayroll = 0 print(" Name\tHours\tPay") print("-----\t-----\t-------")

for i in range(0,len(employeenames)): pay = total_hourly_worked_week[i] * hourly_wage[i] print(employeenames[i],"\t",total_hourly_worked_week[i],"\t$",pay) totalPayroll = totalPayroll + pay print(" Total payroll = $",totalPayroll)

def display_by_name(employeeNames): if not employeenames: print("Employee data had not been read") print("Please read the file before making this choice") else: flag = 0 for i in range(0,len(employeenames)): if employeeNames == employeenames[i]: flag = 1 pay = hourly_wage[i] * total_hourly_worked_week[i] print(employeenames[i],"worked", total_hourly_worked_week[i], "hours at $", hourly_wage[i], "per hour, and earned $", pay)

if flag == 0: print(employeeNames,"not found in the list") #Phase 3 def get_high_low_paid_emp(highlow_choice): if not employeenames: print("Employee data had not been read") print("Please read the file before making this choice") else: if highlow_choice == 'h': highestName = "" highestWage = hourly_wage[0] * total_hourly_worked_week[0]

for i in range(0,len(employeenames)): pay = hourly_wage[i] * total_hourly_worked_week[i] if pay >= highestWage: highestName = employeenames[i] highestWage = pay

print(highestName,"earned $",highestWage)

if highlow_choice == 'l': lowestName = "" lowestWage = hourly_wage[0] * total_hourly_worked_week[0]

for i in range(0,len(employeenames)): pay = hourly_wage[i] * total_hourly_worked_week[i] if pay

#later main()

Thanks!

Here is my code

10 Smith 10 Jones 12.50 4 Miller Baker 15 Ahmad 11.50 4.5 Choi 6.50 20 3.3 2.2 1 0 5 7 6.59 20 7.5 9 1 1 9 20 4 7 2.5 4 4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!