|
2 | 2 | Calculate time and a half pay
|
3 | 3 |
|
4 | 4 | """
|
5 |
| - |
6 |
| - |
7 | 5 | def pay(hours_worked: float, pay_rate: float, hours: float = 40) -> float:
|
8 |
| - """ |
9 |
| - hours_worked = The total hours worked |
10 |
| - pay_rate = Ammount of money per hour |
11 |
| - hours = Number of hours that must be worked before you recieve time and a half |
12 |
| - >>> pay(41, 1) |
13 |
| - 41.5 |
14 |
| - >>> pay(65, 19) |
15 |
| - 1472.5 |
16 |
| - >>> pay(10, 1) |
17 |
| - 10.0 |
18 |
| - """ |
19 |
| - # Check that all input parameters are float or integer |
20 |
| - assert type(hours_worked) == float or type(hours_worked) == int, ( |
21 |
| - "Parameter 'hours_worked' must be of type 'int' or 'float'" |
22 |
| - ) |
23 |
| - assert type(pay_rate) == float or type(pay_rate) == int, ( |
24 |
| - "Parameter 'hours_worked' must be of type 'int' or 'float'" |
25 |
| - ) |
26 |
| - assert type(hours) == float or type(hours) == int, ( |
27 |
| - "Parameter 'hours_worked' must be of type 'int' or 'float'" |
28 |
| - ) |
| 6 | + """ |
| 7 | + hours_worked = The total hours worked |
| 8 | + pay_rate = Ammount of money per hour |
| 9 | + hours = Number of hours that must be worked before you recieve time and a half |
| 10 | + >>> pay(41, 1) |
| 11 | + 41.5 |
| 12 | + >>> pay(65, 19) |
| 13 | + 1472.5 |
| 14 | + >>> pay(10, 1) |
| 15 | + 10.0 |
| 16 | + """ |
| 17 | + # Check that all input parameters are float or integer |
| 18 | + assert (type(hours_worked) is float or type(hours_worked) is int), "Parameter 'hours_worked' must be of type 'int' or 'float'" |
| 19 | + assert (type(pay_rate) is float or type(pay_rate) is int), "Parameter 'hours_worked' must be of type 'int' or 'float'" |
| 20 | + assert (type(hours) is float or type(hours) is int), "Parameter 'hours_worked' must be of type 'int' or 'float'" |
29 | 21 |
|
30 |
| - normal_pay = hours_worked * pay_rate |
31 |
| - over_time = hours_worked - hours |
32 |
| - # Another way |
33 |
| - # over_time_pay = ((over_time * ((over_time + (over_time ** 2) ** 0.5) / (2 * over_time))) / 2) * pay_rate |
34 |
| - over_time_pay = (max(0, over_time) / 2) * pay_rate |
35 |
| - total_pay = normal_pay + over_time_pay |
36 |
| - return total_pay |
| 22 | + normal_pay = hours_worked * pay_rate |
| 23 | + over_time = hours_worked - hours |
| 24 | + # Another way |
| 25 | + """over_time_pay = ((over_time * ((over_time + (over_time ** 2) ** 0.5) / (2 * over_time))) / 2) * pay_rate""" |
| 26 | + over_time_pay = (max(0, over_time) / 2) * pay_rate |
| 27 | + total_pay = normal_pay + over_time_pay |
| 28 | + return total_pay |
37 | 29 |
|
38 | 30 |
|
39 | 31 | if __name__ == "__main__":
|
40 |
| - # Test |
41 |
| - import doctest |
42 |
| - |
43 |
| - doctest.testmod() |
| 32 | + # Test |
| 33 | + import doctest |
| 34 | + doctest.testmod() |
0 commit comments