19. Review: Built-In Functions. Should it return "None" in the console?


<Below this line, add a link to the exact exercise that you are stuck at.>
<In what way does your code behave incorrectly? Include ALL error messages.>
CodeAcademy says my code is fine actually, but shouldn’t my code return either the absolute value of the argument, or the word “Nope”?
<What do you expect to happen instead?>


def distance_from_zero(argument):
if type(argument) == int:
return abs(argument)
if type(argument) == float:
return abs(argument)
return “Nope”

<do not remove the three backticks above>


The reason None or undefined is seen on the console can be found here (credits to haxor), this might be for JS, but is the reason for python.

The thing with the return is that it returns something when the function is called:


now, there are two things you can do, use a print statement so that whatever is returned is printed:

print distance_from_zero(3)

or you can store the result (which is returned) into a variable:

store = distance_from_zero(3)

then print it:

print store

the second method is useful when you want to do something with the data returned from the function, not needed in this case, but i would like to show it either way


I’m sorry, but I am still unclear as to why it doesn’t return Nope or the absolute value? As I understand it, it’s something to do with the fact that CodeAcademy uses a console?


There are two things: None being printed by the console on codecademy. Which i linked to another topic which explains this in detail. One more thing: None and “nope” are NOT the same thing

Then, i tried to explain that return returns something when the function is called. You need to use print on the function call:

print distance_from_zero(3)

in other to print something to the console window