19.Review: Built-in functions: Why my code is broken?


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

I don't get it. Why is it broken?

def distance_from_zero(n):
    if type(n) != str:
        return abs(n)
        return "Nope"



This line:

    if type(n) != str:

Should be:

    if type(n) == int or type(n) == float:


Why? Isn't it the same? If the type is not a string it should be an int or a float. Or there are more types?


Yes, there are a lot more. They are just not covered in the introductory courses. Here is more information on the subject:


Thank you so much. Really. =)
I'll read it all.


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