I am trying to use the return statement. If the y is negative then program will terminate. But it is showing “ValueError: math domain error”
import math
y=-5
def df(y):
if y<=0:
print y, "is negative"
return
result = math.log(y)
print "The log of y is",result
Your return is empty….there is no variable name or value on the same line with “return”. For example, if you wanted to return the value 5, you’d put
If you wanted to return a variable foo, you’d put
Right now you are returning nothing.
Maybe you want this?