def computepay(h, r):
if h > 40:
pay = 40 * r + (h - 40) * r * 1.5
return pay
else:
pay = h * r
return pay
hrs = input("Enter Hours:")
h = float(hrs)
rph = input("Enter Rate:")
r = float(rph)
computepay(h ,r)
so I wrote this function but it doesn't execute; if I change the last line to
p = computepay(h ,r)
print("pay:", p)
OR if I change the function definition to
def computepay(h, r):
if h > 40:
pay = 40 * r + (h - 40) * r * 1.5
print(pay)
else:
pay = h * r
print(pay)
hrs = input("Enter Hours:")
h = float(hrs)
rph = input("Enter Rate:")
r = float(rph)
computepay(h ,r)
then the fuction works properly. Can anyone tell me why it happens? I thought in order to execute a function, just to put the function there and then it executes. Also, what's the difference btw print and return? Thank you!