|
2 | 2 | Calculate time and a half pay |
3 | 3 |
|
4 | 4 | """ |
| 5 | + |
| 6 | + |
5 | 7 | def pay(hours_worked: float, pay_rate: float, hours: float = 40) -> float: |
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'" |
| 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) is float or type(hours_worked) is int, ( |
| 21 | + "Parameter 'hours_worked' must be of type 'int' or 'float'" |
| 22 | + ) |
| 23 | + assert type(pay_rate) is float or type(pay_rate) is int, ( |
| 24 | + "Parameter 'hours_worked' must be of type 'int' or 'float'" |
| 25 | + ) |
| 26 | + assert type(hours) is float or type(hours) is int, ( |
| 27 | + "Parameter 'hours_worked' must be of type 'int' or 'float'" |
| 28 | + ) |
21 | 29 |
|
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 |
| 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 |
29 | 37 |
|
30 | 38 |
|
31 | 39 | if __name__ == "__main__": |
32 | | - # Test |
33 | | - import doctest |
34 | | - doctest.testmod() |
| 40 | + # Test |
| 41 | + import doctest |
| 42 | + |
| 43 | + doctest.testmod() |
0 commit comments