Question: For Python 3 Modify this code to include an employee class. You need to write getters and setters for the name, hours, and rate instance
For Python 3
Modify this code to include an employee class. You need to write getters and setters for the name, hours, and rate instance variables. The setters for hours and rate should validate the data (make sure it is greater than 0). Make sure to use the setters. I should not be able to use a method to set a negative value for hours or rate. The get_input and calc_pay functions should become methods of the class. They will need a few modifications. The get_input function should set the appropriate instance variables instead of returning them. The calc_pay will no longer need arguments because hours and hourly rate are now instance variables.
Sample Run:
How many employees do you want to enter? 3
Enter a name: Guido van Rossum
Enter hours worked: 42.5
Enter hourly rate: 285.11
Guido van Rossum should be paid $12,473.56
Enter a name: Blaise Pascal
Enter hours worked: 45
Enter hourly rate: 294
Blaise Pascal should be paid $13,965.00
Enter a name: Charles Babbage
Enter hours worked: 51
Enter hourly rate: 268
Charles Babbage should be paid $15,142.00
The total amount to be paid is $41,580.56
The average employee is paid $13,860.19
def data(): name=input("Enter a name") hours=float(input("Enter hours worked")) rate=float(input("Enter hourly rate:")) return (name, hours, rate)
def pay_zzz(hours,rate): pay=0 if hours>40: pay=(40*rate)+((hours-40)*1.5*rate) else: pay=hours*rate return pay
def call(): employee=int(input("How many employees do you want to enter?")) total=0 print(" ") for i in range(employee): (name,hours,rate)=info() pay = pay_zzz(hours,rate) total+= pay print("{} should be paid ${:,.2f}".format(name,pay)) print(" ") print("The total amount to be paid is ${:,.2f}".format(total)) print("The average employee is paid ${:,.2f}".format(total/employee))
call()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
