- Notifications
You must be signed in to change notification settings - Fork 46.7k
/
Copy pathtime_and_half_pay.py
40 lines (33 loc) · 1.03 KB
/
time_and_half_pay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
Calculate time and a half pay
"""
defpay(hours_worked: float, pay_rate: float, hours: float=40) ->float:
"""
hours_worked = The total hours worked
pay_rate = Amount of money per hour
hours = Number of hours that must be worked before you receive time and a half
>>> pay(41, 1)
41.5
>>> pay(65, 19)
1472.5
>>> pay(10, 1)
10.0
"""
# Check that all input parameters are float or integer
assertisinstance(hours_worked, (float, int)), (
"Parameter 'hours_worked' must be of type 'int' or 'float'"
)
assertisinstance(pay_rate, (float, int)), (
"Parameter 'pay_rate' must be of type 'int' or 'float'"
)
assertisinstance(hours, (float, int)), (
"Parameter 'hours' must be of type 'int' or 'float'"
)
normal_pay=hours_worked*pay_rate
over_time=max(0, hours_worked-hours)
over_time_pay=over_time*pay_rate/2
returnnormal_pay+over_time_pay
if__name__=="__main__":
# Test
importdoctest
doctest.testmod()