19. Review: Built-In Functions



Here is my code plus the error message I'm getting:

What could I be doing wrong? :confused:


abs() is a function that returns the absolute value of whatever is placed inside the parentheses. In this case we want the absolute value of m, so we would write return abs(m)


That solved it! Thanks! :relieved:


Hello , Can anyone help me with this. Why am I getting a "none" here ??


Your function is printing "nope" when it should be returning "nope".


Even when I return "nope" why is it printing "none" in the console ??


Have you tried putting nope in quotes i.e. "Nope" ?


The extra None that is printed in the console is a result of how Codecademy processes your code. If you were to run the same code in another interpreter you would not see that None. If you would like to test this you can use the labs repl.it


Exactly ! That's what my question is.. I don't get it in other
interpreters. How am I supposed to complete this exercise now? And
continue with the course. Please give some suggestion.


The problem is with your if statement. Currently you have:

if type(d) == int or float:

And I understand why it would be tempting to write it that way, but with programming we need to be very specific so it actually needs to be written as:

if type(d) == int or type(d) == float

Also, as @muzakir said, make sure you have:

    return 'nope'


Thank you so much mkordik. It's solved but I still don't understand why it didn't throw a syntax error or something


The syntax wasn't wrong in terms of Python being able to process it. It was wrong because it wasn't checking what you really wanted to check.

Here is a good post on why it did what it did:


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

And Voila!


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