Guys,

What is wrong with my compution here when "hrs" entered is 45?
The end result expected si 498.75 but it keeps failing to compute second portion correctly (please see below and attached screenshot).

hrs = input("Enter Hours:")
h = float(hrs)
OvrTimehrs = float(hrs) - float(40)
HourlyRate = input("Enter Hourly Rate:")
OvertimeRate = input("Enter Overtime Rate:")
if float(h) <= 40 :
    TotalPay = float(hrs) * float(HourlyRate)
if float(h) > 40 :
    TotalPay = ((float(hrs) * float(HourlyRate)) + ((float(OvrTimehrs) * float(OvertimeRate) *   float(HourlyRate))))
print(hrs)
print(OvrTimehrs)
print(TotalPay)  

If I enter 45 the end result for second "if" statement is giving "TotalPay" of 551.25 when it should be 498.75.

Enter Hours:45
Enter Hourly Rate:10.5
Enter Overtime Rate:1.5
551.25

OverTimePay.PNG

Thanks,

Alex

You are calculating

TotalPay = ((float(hrs) * float(HourlyRate)) + ((float(OvrTimehrs) * float(OvertimeRate) *   float(HourlyRate))))

You are using the total hours multiplied by your hourly rate. You want 40 * HourlyRate. That would give you the answer you expect.

commented: Oh! That was a Duh! moment in my logic. Thank you Reverend Jim. +0

That was a Duh! moment

We've all been there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.