Skip to content

Commit 2d56591

Browse files
Update time_and_half_pay.py
1 parent c4be33e commit 2d56591

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

Diff for: financial/time_and_half_pay.py

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
22
Calculate time and a half pay
3-
43
"""
54

65

@@ -9,6 +8,7 @@ def pay(hours_worked: float, pay_rate: float, hours: float = 40) -> float:
98
hours_worked = The total hours worked
109
pay_rate = Ammount of money per hour
1110
hours = Number of hours that must be worked before you recieve time and a half
11+
1212
>>> pay(41, 1)
1313
41.5
1414
>>> pay(65, 19)
@@ -17,23 +17,20 @@ def pay(hours_worked: float, pay_rate: float, hours: float = 40) -> float:
1717
10.0
1818
"""
1919
# Check that all input parameters are float or integer
20-
assert type(hours_worked) is float or type(hours_worked) is int, (
20+
assert isinstance(hours_worked, float) or isinstance(hours_worked, int) (
2121
"Parameter 'hours_worked' must be of type 'int' or 'float'"
2222
)
23-
assert type(pay_rate) is float or type(pay_rate) is int, (
24-
"Parameter 'hours_worked' must be of type 'int' or 'float'"
23+
assert isinstance(pay_rate, float) or isinstance(pay_rate, int) (
24+
"Parameter 'pay_rate' must be of type 'int' or 'float'"
2525
)
26-
assert type(hours) is float or type(hours) is int, (
27-
"Parameter 'hours_worked' must be of type 'int' or 'float'"
26+
assert isinstance(hours, float) or isinstance(hours, int) (
27+
"Parameter 'hours' must be of type 'int' or 'float'"
2828
)
2929

3030
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
31+
over_time = max(0, hours_worked - hours)
32+
over_time_pay = over_time * pay_rate / 2
33+
return normal_pay + over_time_pay
3734

3835

3936
if __name__ == "__main__":

0 commit comments

Comments
 (0)