19.review built in functions


#1

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

this is showing an error and i dont understand what is wrong!!


#3

I had the same issue. After the error, I used this code:

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

I called type(n) before the if statement. After I did this, it worked.


#4

print "Nope should be print "Nope".

P.S. Please format your code. Thanks!


#5

You should not need to call type(n) like that in a single statement by itself. Your code should work fine without it.


#6

@julesrck Thnx a lot for this one! :relaxed: