[SOLVED] write your pay computation with time-and-a-half for overtime and create a function called computepay which takes two parameters (hours and rate)

Issue

For the above question i have written this code . Math formula is correct but it is not giving the correct answer where is the fault?

def computepay(hours, rate):
    if hours<=40:
        pay = hours * rate
    else:
        pay = (((hours-40)*rate)*1.5)+rate*40
        return pay
x = input("Enter hours: ")
y = input("Enter rate: ")
a = float(x)
b = float(y)
pay = computepay(a, b)
print("Pay: ", pay)

Solution

When hours is less than or equal to 40, computepay() doesn’t return anything. Try changing the indent of the return pay line by four spaces, so it’s indented by the same amount as the else::

def computepay(hours, rate):
    if hours<=40:
        pay = hours * rate
    else:
        pay = (((hours-40)*rate)*1.5)+rate*40
    return pay

Answered By – Nathan Mills

Answer Checked By – Cary Denson (BugsFixing Admin)

Leave a Reply

Your email address will not be published.