Help with Functions 19



Oops, try again. It looks like you have a NameError. Maybe you forgot to create a function called distance_from_zero? Check the error message for more info! - global name 'distance_from_zero' is not defined.....I have done this

def distance_from_zero('arg'):
if type('arg') == int
return abs('arg')
elif type('arg') == float;
return abs('arg')
return "Nope"


The parameter variable cannot be a string. Write variables with no quotes.

Be sure to indent the code body of the function and the if..elif statements. Check your syntax on if and elif.


What you need to do is detect the type of the argument. Then compare it to the data type. If it's the same then return the result, else the other result.

And @mtf is right, no string in the parameter variable.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.