Review Built-In Functions New Idea!


Is this code correct for other editors?

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


Hi @scriptninja24101,

A problem is that if n is of type bool, the function does not behave as Codecademy expects. The function should determine whether n is of type int or float, and if so, it should pass n to the abs function. For any other type, it should not.


The issue is that I myself have tried this with if type(n) == float or int: and it still says that it returns one when the input True is passed


Hi @phoenixa,

To perform the comparison correctly, you need ...

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


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