An employee class would look something like this:
class Employee:
def __init__(self, name, pay_rate, hours):
self.name = name
self.pay_rate = pay_rate
self.hours = hours
def overtime(self):
"""Return overtime hours."""
return max(0, self.hours - 40)
def pay(self):
"""Return pay for this latest pay period."""
return self.pay_rate * (self.hours + 0.5 * self.overtime())
def __str__(self):
"""Return pretty string."""
return f"{self.name:30} Pay Rate = {self.pay_rate:6.2f}, Hours Worked = {self.hours:6.2f}, Pay = {self.pay():8.2f}"
Cleaner than a dictionary because you don't need to use keys to access the values, plus it can compute pay, removing that burden from the payroll class.
@
Pedroski55, did you read the assignment description in the initial post? There was no mention of supporting multiple companies, though that is easily supported by loading a different payroll file. All that is mentioned is that the payroll class must have payroll data for "many employees", support adding new employees (input data), compute pay, and display pay. There is no mention of how an employee is represented other than the attributes: name, hours worked, pay rate and total pay. I must admit I am guilty of missing some details. For some reason I got it stuck in my head the employee data file would be a json file when the instructions explicitly say it should be some sort of CSV.
Using the payroll class is defined a little better. A main program creates an instance of the payroll class, uses the class to read employee data from a file, and upon exiting the program uses the payroll class to write employee data to a file.