Review: Built-in Functions


#1

I'm stuck with the review of built-in functions, please help! Here's my code, I keep getting an error "Oops, try again. Your function seems to fail on input -10 when it returned 'Nope' instead of '10'"

I can't figure it out for the life of me.

def distance_from_zero(hei): 

    if type(hei) == 'int' or type(hei) == 'float':
        return abs(hei)
        print abs(hei)
    else:
        return "Nope"

print distance_from_zero(20)

#2

please change 'int' and 'float' into int and float on line 3. they are keywords so should be without ' '


#3

Thanks a ton! Jeez, I feel stupid now, how did I not see that :smiley:


#4

hi I am new to this:) i am stuck at
def distance_from_zero(num):

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

print distance_from_zero(30)

Got an error "Oops, try again. Your function seems to fail on input True when it returned 'None' instead of 'Nope'"

Can someone explain why?
Edit: I forgot return "None":slight_smile: