Review Built-In Functions New Idea!


#1


Is this code correct for other editors?

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


#2

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.


#3

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


#4

Hi @phoenixa,

To perform the comparison correctly, you need ...

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

#5

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