Home > front end >  write your pay computation with time-and-a-half for overtime and create a function called computepay
write your pay computation with time-and-a-half for overtime and create a function called computepay

Time:03-22

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)

CodePudding user response:

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
  • Related