Question: In this week's scenario, the clock system for our store will continue to send us a file that lists each employee that worked that week
In this week's scenario, the clock system for our store will continue to send us a file that lists each employee that worked that week along with the hours worked for each day. That file is named "work_log.txt" and has the same format of name tab hours tab hours...
A file named "positions.txt" is maintained by the store manager. It contains the names of each employee along with their job title. The format is name tab title. For example, "Bob Smith Store Manager". Each line of the file is a different employee.
Pay rates for each position are set by the headquarters office in Atlanta. That data file is named "pay_rates.txt". Its format is title tab rate. For example, "Store Manager 31.00". Each line of the file is a different job title for stores in our company.
Using the data in those three files, and using the same overtime rules as the previous assignment, write a Python program that will compute each employee's pay for the past week. For each employee that worked that week, output their name, title, total hours worked, and pay.
Note: total hours worked is just a sum of the hours inside work_log.txt. Two employees earning the same pay rate and working the same total hours might have different amounts of pay for the week, because their overtime might be different.
Using the three attached files, your program should output something like the following. Be sure to align the columns of data.
Employee Hrs Worked Pay ----------------------------------------------------- Bob Smith (Store Manager) --> 40.0 --> $1240.00 Sue Jones (Asst Store Mngr) --> 41.5 --> $1161.56 John Williams (Shift Manager) --> 40.0 --> $ 800.00 Mike Johnson (Shift Manager) --> 26.0 --> $ 540.00 Jane Brown (Shift Manager) --> 17.0 --> $ 340.00 Miller Davis (Service Rep) --> 20.0 --> $ 276.75 Davis Miller (Service Rep) --> 43.0 --> $ 600.75 Rich Thompson (Stock Clerk) --> 50.0 --> $ 660.00 Joe Slacker (Stock Clerk) --> 16.0 --> $ 192.00 Jaden Moore (Cashier I) --> 28.0 --> $ 350.00 Haden Wilson (Cashier I) --> 34.0 --> $ 425.00 Aiden Anderson (Cashier I) --> 40.0 --> $ 550.00 Gretta Anderson (Cashier I) --> 40.0 --> $ 550.00 Emma Harris (Cashier I) --> 24.0 --> $ 300.00 Olivia Williams (Cashier II) --> 28.0 --> $ 420.00 Taylor Martin (Cashier II) --> 26.0 --> $ 420.00 ----------------------------------------------------- Total Payroll: $8826.06
Error Checking: Check that each of the three files exists. If a file is missing, just print an error message and exit. If we were deploying this program in a business it would need to be robust. Suppose an employee's title was "Cashier III" but there was no pay rate from corporate headquarters for that title. That type of problem will cause your homework to crash. We could handle those potential problems with extra if statements, but that is beyond the scope of this assignment.
Hints: Again, do this is small pieces. The first version of this program for me was just printing each employee's name from work_log.txt and matching it to their title in positions.txt.
My second task was to determine their pay rate. That did not work on my first or second tries. My program knew that Bob Smith was the Store Manager, but the dictionary holding the job titles did not contain a "Store Manager". After a bit of debugging, I discovered that dictionary contained a key of "Store Manager " instead of "Store Manager". The split command keeps the return character at the end of each line. So, I had to use strip() to cut off the extra characters before I put the titles in a dictionary.
Once I knew each person's pay rate, it was easy to copy-and-paste the loop and if statements from the previous assignment that calculated overtime pay. Of course, that code needs to be edited just a bit.
My last task was to format the output.
Here are the txt files:
work_log.txt
Bob Smith 0 8 8 8 8 8 0 Sue Jones 4 0 8 11 10.5 0 8 John Williams 0 8 8 8 8 8 0 Mike Johnson 8 0 0 0 0 10 8 Jane Brown 0 4 4 4 5 0 0 Miller Davis 5 0 0 0 0 9 6 Davis Miller 0 9 9 9 8 8 0 Rich Thompson 0 10 10 10 10 10 0 Joe Slacker 5 3 3 0 0 0 5 Jaden Moore 8 8 0 0 0 4 8 Haden Wilson 8 8 0 0 4 6 8 Aiden Anderson 0 10 10 10 10 0 0 Gretta Anderson 0 0 10 10 10 10 0 Emma Harris 4 0 8 8 0 0 4 Olivia Williams 0 4 4 4 8 8 0 Taylor Martin 3 3 0 0 0 10 10
positions.txt
Bob Smith Store Manager Sue Jones Asst Store Mngr John Williams Shift Manager Jane Brown Shift Manager Mike Johnson Shift Manager Miller Davis Service Rep Davis Miller Service Rep Joe Slacker Stock Clerk Rich Thompson Stock Clerk Emma Harris Cashier I Olivia Williams Cashier II Gretta Anderson Cashier I Taylor Martin Cashier II Aiden Anderson Cashier I Haden Wilson Cashier I Jaden Moore Cashier I
pay_rates.txt
Store Manager 31.00 Asst Store Mngr 26.25 Shift Manager 20.00 Service Rep 13.50 Cashier I 12.50 Cashier II 15.00 Stock Clerk 12.00
Code Example provided:
# Compare home city of all CBA students # to Top 50 most populated cities in SC # -------------------------------------
# - - - - - - - - - - - - - - - - - - - - - - # Build a dictionary where # key = city in SC # value = # of students from that city cityDict = {} inFile = open ("Cities.txt","r") for city in inFile : city = city.replace("SC","").strip() if city not in cityDict : cityDict[city] = 1 else : cityDict[city] += 1 inFile.close()
# - - - - - - - - - - - - - - - - - - - - - - # copy that dictionary, but sorted sortedCities = dict(sorted(cityDict.items(), reverse=True, key=lambda item: item[1]))
# - - - - - - - - - - - - - - - - - - - - - - # build a list from Populations.txt # SC city with highest population is first pops = [] infile = open ("Populations.txt","r") for x in infile : lineData = x.split("\t") pops.append(lineData[1]) inFile.close()
# - - - - - - - - - - - - - - - - - - - - - - # output the results print(" Students City Population Rank") print("---------------------------------------") msg = "{:3d} - {:3d} - {:15s} - {}" count=0 for ck,cv in sortedCities.items() : # number each item count += 1 # find the city in the population list if ck in pops : rank = pops.index(ck) + 1 else : rank = "?" # print the data print (msg.format(count,cv,ck,rank))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
