Python function: Error with overtime while creating a wage function -
i trying create wage function using python 3.50 goes follows: user enters hourly pay "x", , hours worked "y". trying implement overtime portion if hours worked greater 40 person paid 1.5 times more hours. inputting wage (10,45) , returning 525 when should returning 475, can me pick out error? appreciated, thank time in advance.
def wage(x, y): if y > 40: ehours = y - 40 overtime = x * 1.5 * ehours return x * y + overtime else: return x * y
well, should paid 0.5 (not 1.5 extra), code should this:
def wage(x, y): if y > 40: ehours = y - 40 overtime = x * 0.5 * ehours return x * y + overtime else: return x * y
alternatively, might easier (but not better) this:
def wage(x, y): return x * y + (0.5*x*max(y-40, 0))
Comments
Post a Comment