Skip to content

Commit 23685d6

Browse files
authored
Create time&half-pay.py
1 parent 5afe029 commit 23685d6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Diff for: financial/time&half-pay.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
Calculate time and a half pay
3+
4+
"""
5+
def pay(hours_worked, pay_rate, hours = 40):
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+
"""
11+
normal_pay = hours_worked * pay_rate
12+
over_time = hours_worked - hours
13+
# Another way
14+
# over_time_pay = ((over_time * ((over_time + (over_time ** 2) ** 0.5) / (2 * over_time))) / 2) * pay_rate
15+
over_time_pay = (max(0, over_time) / 2) * pay_rate
16+
total_pay = normal_pay + over_time_pay
17+
return total_pay
18+
19+
20+
if __name__ == "__main__":
21+
# Test
22+
print(pay(41, 1))
23+
print(pay(65, 19))
24+
print(pay(10, 1))

0 commit comments

Comments
 (0)