⎻Define a function to compute the weekly payment for an employee with two arguments: 1. number of hours worked and 2. pay rate ⎻The overtime pay rate (overtime is time outside the ordinary hours per week which is 8) is 1.5 * pay rate. For example, if someone works for 10 hours, and payrate is $10/hour, total = 8 * 10 + 2 * 1.5 * 10 ⎻The function returns the weekly pay for an employee, you can assume all the arguments are valid
时间: 2024-03-16 16:43:58 浏览: 56
Sure, here's an example Python code that defines a function to compute the weekly payment for an employee:
```python
def compute_weekly_pay(hours_worked, pay_rate):
regular_hours = min(hours_worked, 8)
overtime_hours = max(hours_worked - 8, 0)
overtime_rate = 1.5 * pay_rate
return regular_hours * pay_rate + overtime_hours * overtime_rate
```
This function takes two arguments `hours_worked` and `pay_rate`, and returns the weekly pay for the employee based on the number of hours worked and the pay rate. It first computes the regular hours worked (up to 8 hours), and the overtime hours worked (any hours worked beyond 8). It then calculates the overtime pay rate, which is 1.5 times the regular pay rate. Finally, it returns the total pay for the week, which is the product of regular hours worked and pay rate, plus overtime hours worked and overtime pay rate.
阅读全文