19/19 name error


#1

I keep getting a name error for this code
def distance_from_zero(n):
if type(n) == int or type(n) == float:
return abs(n)
else:
return "Nope"

I've tried all of these codes and remade and created different versions of mine and I still get this name error
Please help


#2

ton code n'est pas indenté
I keep getting a name error for this code
def distance_from_zero(n):
if type(n) == int or type(n) == float:
return abs(n)
else:
return "Nope"


#3

This is almost there it fixes the name error at least now i just have to figure out the other error

def distance_from_zero(n):
return type(n) == int or type(n) == float

if type(n) == int or type(n) == float:
    return abs(n)
else:
    return "Nope"

distance_from_zero(10)


#4

Remember that in python indenting and spacing can do a lot


#5

This is the proper way to use it you dont even need to use the return.

def distance_from_zero(n):
if type(n) == int or type(n) == float:
return abs(n)
else:
return "Nope"
distance_from_zero(10)


#6

I tried your code but i still get the name error


#7

The "proper" way to do this in python is by using a try statement. Not that the judge will accept it but none the less it is the "proper" way to do it in python.

EXAMPLE:

def distance_from_zero(number):
    try:
        return abs(number)
    except TypeError as error:
        print("You failed to enter a valid response: %s" % error)

OR

def distance_from_zero(number):
    if type(number) == (float or int):
        return abs(number)
    else:
        print("You failed to enter a valid response")