考虑到加班费与正常工资率,似乎需要了解雇员在每一类别工作的时间。 有鉴于此,这里是一个简单的例子,可以说明一些关键概念。
例:
def computepay(hours, rate):
return hours * rate
regular_rate = float(input("Hourly rate in dollars: "))
regular_hours = float(input("Regular hours worked: "))
overtime_hours = float(input("Overtime hours worked: "))
regular_pay = computepay(regular_hours, regular_rate)
overtime_pay = computepay(overtime_hours, regular_rate * 1.5)
total_pay = regular_pay + overtime_pay
print(f"This pay period you earned: ${total_pay:.2f}")
产出:
Hourly rate in dollars: 15.00
Regular hours worked: 40
Overtime hours worked: 10
This pay period you earned: $825.00