Build in Functions


The error that I get but I don't get the functions structure and every time I get the error that the function is not defined...
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

Could someone help me understanding the structure and my error please.

def distance_from_zero():
    distance_from_zero = 2 ** 5
    If type(distance_from_zero) == int or type(distance_from_zero) == float:
        print abs(distance_from_zero)
        print "Nope"


Okay, here you go.

def distance_from_zero(d): ##definition of function called distance_from_zero
    if type(d) == int or type(d) == float: ##check if data type (argument) is of integer or float)
        return abs(d)
        return "Nope" ##returns this when previous fail.

See explanation as comments.

I hope this helps. :slight_smile:


Hi ferlee!
It looks like you have forgotten to assign an argument for your function. This question is looking to pass an integer into the function and have it return the the distance from zero.

Def distance_from_zero(_Argurments go here_) # what ever you place here holds the place for content that is to be passed into the function.

Codecademey will be checking this problem by calling this function on different numbers like this:


Hope this helps!


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