 # Not getting the correct calculation for extra hours payment program

when hour = 45, rate =10 and extra hour = 5, then output should be 475.0 but I am getting output as 525.0 using below program. Please help me to locate out my mistake.

``````hour=float(input('pleae enter the working hours: '))
rate=float(input('pleae entr the rate: '))
exthr=float(hour-40)
if(hour > 40):
salary=((hour*rate) + (1.5*exthr*rate))
print(hour, rate, exthr, salary)
else:
salary=(hour*rate)
print (salary)``````
1 Like

you need to define extrahour and then:
replace (hourrate) with((hour - exthr) * rate) for the expression where the if condition holds true. Hope that helps. I’m having issue running this code in Jupyter. I am using this thread as it is related to the same assignment. Moderators, please move this post if you think it needs a new thread.

Is there something wrong with this code below? I am not getting the user prompt. I simply get another notebook input line. How do I debug my code in Jupyter?

``````def computepay():
hours = float(input("Enter number of hours: "))
rate = float(input("Enter hourly rate: "))
timeandhalf_hours = (hours - 40)
if hours > 40:
salary = ((hours - timeandhalf_hours) * rate) + (1.5 * rate * timeandhalf_hours)
print(salary)
else:
salary = hours * rate
print(salary)
computepay()``````
1 Like

Yes! this worked.
Thanks Gopi 1 Like

No worries. Happy to help

My code is working now.

Hello Gopi and Prashant

Im new to this environment. This might be an old topic but i have question. Pls correct my understanding if wrong. The salary is computed as

Actual rate for 40 hrs(here) + Rate for any extra hours

Thanks
SR

Yes your business logic is on track. Multiply the standard rate by the standard hours (40 standard hours assumed in this example). Add to that the total of multiplying the extra rate by any additional hours in excess of the standard 40 hours. Adding the two together will give you the salary. For this example, remember the extra rate is the standard rate x 1.5.

Hope this helps.

1 Like