19. review built in functions im confused


i keep getting this message and i'm really confused.
Oops, try again. Your function seems to fail on input True when it returned '1' instead of 'Nope

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


We need to test hola for both types using the same function:

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


The hint says his way should work


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



Just saw this comment so went ahead and checked. In Python3 IDLE,

>>> type(3.5) == int or float
<class 'float'>

Python is treating True as 1 in the type check, so returns 1. Should have taken a closer look.

>>> isinstance(True, int)

>>> def distance_from_zero(hola):
    if type (hola) == int or float and not isinstance(hola, bool):
        return abs(hola)
        return "Nope"

>>> distance_from_zero(True)


def distance_from_zero(w):
if type(w) == int:
return abs(w)
elif type (w) == float:
return abs(q)
return "Nope"


What is wrong here? I really cant understand///


q is not defined, but w is. Check the Hint for an example.