Help with 19. Review: Built-in functions


#1



Review: Built-In Functions


My code is throwing a very weird error message. I am not sure where that number letter combo is even coming from...

Anyways, as always thanks in advance.

Oops, try again. Your function seems to fail on input -10 when it returned 'function distance_from_zero at 0x7f3695397848' instead of '10'


def distance_from_zero (num):
    return distance_from_zero
    if  type(num) == int or float:
        return abs(num)
    elif type (num):
        return abs(num)
    else:
        return 'nope'


#2

a function ends the moment a return keyword is reached, in other words here:

return distance_from_zero

you return the function object


19. Review: Built-In Functions Please help!
#3

So now with the first 'return' commented out, I am getting this error:

Oops, try again. Your function seems to fail on input True when it returned '1' instead of 'Nope'


#4

your if condition:

if  type(num) == int or float:

you need to do comparison at both sides of the or operator, otherwise python will evaluate if float is true.

I don't see why you would need an elif for this program


#5

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