I am stumped with how to write this in python code. Can anyone help?
***For hours over 60, you need to calculate the overage above 60 to multiply at the 2x pay rate + the hours between 40 and 60 to be compensated at 1.5x rate + the first 40 hours at the regular rate.****
You should at least provide your initial effort to solve your problem with your question, but how about this:
def calculate_total(hours, rate):
if hours > 60:
over_60 = hours - 60
else:
over_60 = 0
if hours > 40:
over_40 = hours - 40 - over_60
else:
over_40 = 0
under_40 = hours - over_60 - over_40
return under_40 * rate + over_40 * rate * 1.5 + over_60 * rate * 2
You may the call this function using:
calculate_total(75, 12)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.