In: Computer Science
Python Rephactor
Compute Take Home Pay
Write a function called compute_pay that accepts arguments representing the hourly wage of an employee and the number of hours that employee worked this week. The function should return the take home pay owed to the employee as a floating point value rounded to two decimal places.
The normal work week is 40 hours, and the company pays employees "time and a half" for overtime. So, the total wages is the sum of regular wages and overtime wages. Regular wages are the hours worked (up to 40) times the hourly wage. Overtime wages are any hours over 40 times the hourly wage times 1.5.
The employee's take home pay is the total wages minus taxes and medical costs. Taxes are 20% of the total wages, and medical costs are 10% of the total wages.
Suppose an employee makes $12.25 per hour and has worked 45 hours this week. The take home pay for that employee is 40 hours times 12.25, plus 5 hours times 18.50 (time-and-a-half), minus taxes and medical, for a total of $407.31.
def compute_pay(rate,hours):
wage=rate*min(hours,40)
#overtime rate
orate=rate*1.5
#add overtime amount
if(hours>40):
wage+=(hours-40)*orate
#deduction = 20 + 10 =30%
wage=wage*0.7
return round(wage,2)
======
Output:
======
The function take hourly rate and no. of hours as input.
Intially it calculates wage for regular hours (<=40) and then adds overtime to it by multiplying it with the overtime rate (orate=rate*1.5).
Since deductions made are 20% for tax and 10% for medical total deduction are 30%. So remaining part is 70%.
So 70% of wage is returned by rounding it two decimal places.