My Function Returns "None"
I am new to Python and I was trying to solve this exercise, but keep getting 'None' output. The question asked for a program in which the input is hours and rate and the output is
Solution 1:
return
will return None if you don't give it anything else. Try return pay
Solution 2:
You have to specify what to return in the return
statement:
def double_it(x):
return x*2
Note that x*2
after the return
statement.
Solution 3:
My function returns “None”
You function does not return anything. You meant to return pay
:
def compute_pay(h, r):
if h <= 40:
pay = h*r
elif h > 40:
pay = (((h-40)*1.5)*r+(40*r))
return pay
And I think you may shorten your code using the ternary if/else
:
def compute_pay(h, r):
return h * r if h <= 40 else (((h - 40) * 1.5) * r + (40 * r))
Post a Comment for "My Function Returns "None""