Question: HERE IS THE QUESTION The weekly hours for all the employees at your company are stored in the file called Employee_hours.txt . Each row records
HERE IS THE QUESTION
The weekly hours for all the employees at your company are stored in the file called Employee_hours.txt. Each row records an employees seven-day work hours with seven columns. For example, the following table stores the work hours for eight employees:
| Employee | Su | M | T | W | Th | F | Sa |
| 1 | 2 | 4 | 3 | 4 | 5 | 8 | 8 |
| 2 | 7 | 3 | 4 | 3 | 3 | 4 | 4 |
| 3 | 3 | 3 | 4 | 3 | 3 | 2 | 2 |
| 4 | 9 | 3 | 4 | 7 | 3 | 4 | 1 |
| 5 | 3 | 5 | 4 | 3 | 6 | 3 | 8 |
| 6 | 3 | 4 | 4 | 6 | 3 | 4 | 4 |
| 7 | 3 | 7 | 4 | 8 | 3 | 8 | 4 |
| 8 | 6 | 3 | 5 | 9 | 2 | 7 | 9 |
Write a program that reads the employee information from the file and store it in a two-dimentional list. Then displays the following information:
employees and their total hours in decreasing order of the total hours (For example, using the above data employee 8 would be listed first with a total of 41 hours, employee 7 would be listed next with a total of 37 hours, etc.)
total hours worked for each day of the week: Sunday through Saturday
You must only use Python tools we have covered in class or the textbook. You must not use anything found on Chegg, Stackoverflow, etc.
** You may only use tools and techniques that we covered in class. You cannot use tools, methods, keyword, etc. from sources outside of what is covered in class.
HERE IS MY CODE. I WANT TO MAKE SURE I PROGRAMMED EVERYTHING CORRECTLY.
def stringListToIntList(a_list): empty = [] for elem in a_list: empty.append(int(elem)) return (empty)
fhand = open("c:\\TestData\\Employee_Hours.txt", "r")
list1 = [] for i in fhand:
x = i.split(" ") x = " ".join(x) list1.append(x) fhand.close
list1.pop(0) num_list = [] list2D = [] num2 = [] for elem in list1: x = elem.split() num_list.append(x)
for elem in num_list: x = stringListToIntList(elem) num2.append(x)
for elem in num2: y = [elem[0], elem[1:]] list2D.append(y)
def listsum(list): return sum(list[1])
list2D.sort(reverse=True, key=listsum) # print(list2D)
for elem in list2D: print( f"Employee number {elem[0]} total number of hours {sum(elem[1])} for the week.")
day = 0 daylist = [] day_of_week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] while day < 7: for elem in list2D: daylist.append(elem[1][day]) print(f'{day_of_week[day]: <10} total of {sum(daylist)} hours worked') daylist = [] day += 1
done = input("PRESS ENTER TO QUIT!!!")
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
