168k views
1 vote
The function below takes two numeric parameters. The first parameter specifies the number of hours a person worked and the second the number of dollars that they earn each hour. Compute the value of their weekly pay check. Any time worked beyond 40 hours, is considered overtime. Any overtime earns double pay (but only on the hours beyond the first 40). (python)

Function:

def compute_pay_with_overtime(hours_worked, hourly_rate)

User Mrdrbob
by
7.0k points

1 Answer

4 votes

Answer:

def calculate_pay(total_worked_hours, rate_per_hour):

if total_worked_hours > 40:

return (40 * rate_per_hour) + ((total_worked_hours - 40) * 2 * rate_per_hour)

else:

return total_worked_hours * rate_per_hour

Step-by-step explanation:

  • Create the calculate_pay function that takes 2 parameters.
  • Inside the function check whether the total_worked_hours is greater than 40 and then return the pay by calculating with the help of formula for work over 40 hours.
  • Otherwise return the pay by multiplying the total_worked_hours with rate_per_hour.
User Omkar Bandkar
by
7.6k points