Review: Built In Functions---Please Help


#1

This is the error I keep receiving:

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 'math' is not defined

Does anyone know what is wrong? Please help! This is my code:

def distance_from_zero(number):
    if type(number)==int or type(number)==float:
        return math.abs(number)
    else:
        return "Nope"

#2

@redsoxlove,
abs() is a so-called built-in function.
https://docs.python.org/2/library/functions.html?highlight=abs#abs

Thus remove the math library-keyword....!!


#3

You are getting error because in your snip-code
"return math.abs(number)"
Just try
return abs(number)
:slight_smile:


#4

Thanks! This was very helpful.