19. Review: Built-In_Functions


#1
def DistanceFromZero(number):
    if type(number) == int:
        return abs(number)
    elif type(number) == float:
        return abs(number)
    else:
        return "Nope"

Help!!!!!!!!!!!!:cold_sweat:


#2

@powergirly,

Maybe you should try

type(number) is int

as condition.....


#3

should be,

def distance_from_zero(number):

The rest of the code will work as expected.

is also valid and does pass the correctness test.


#4

def distance_from_zero(arg):
if type(arg) is int or type(arg) is float:
return abs(arg)
else:
return "Nope"

both == and is worked for me at if part...

JUST INDENT EVERYTHING...


#5

I would suggest:

isinstance(number, int)

As explained here.


#8

A post was split to a new topic: need help here distance from zero


#12