19/19 what is the problem?


#1

Hi,
I got 19/19 by using

def distance_from_zero(b):
hi = type(b)
if hi == int or hi ==float:
    return abs(b)
else:
    return "Nope"

but i don't understand why this didn't work

def distance_from_zero(b):
hi = type(b)
if hi == int or float:
    return abs(b)
else:
    return "Nope"

Why must hi be retyped? is it because of the type function? it seems to work fine with a case like

if g== "Yes" or "No"

In another problem


#2

Hey, mine worked with this one but I'm still a bit lost to explain why.

def distance_from_zero(num):

if type(num) == int or type(num) == float:
    return abs(num)
else:
    return "Nope"

#11

Mine is exactly the same but won't work :confused:

def distnce_from_zero(num):

if  type(num) == int or type(num) == float:
    return abs(num)
else:
    return "Nope"

#12

Identation maybe?

what kind of error do you have when you run it?


#13

This is the error... by code academy

Oops, try again. Your function seems to fail on input True when it returned '1' instead of 'Nope'


#14

i just kept mine simple
def distance_from_zero(x):
if type(x) == int or type(x) == float:
return abs(x)
else:
return "Nope"
Make sure you have a capital "N" or it will not work as i found out.


#15

Hey there guys, I have the same problem as nixka, my console gives me this error:

Oops, try again. Your function seems to fail on input True when it returned '1' instead of 'Nope'

I have copied your code and pasted it as mine, but still that did not work.

I decided to do everything over again and i now have this:

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

Why is this still showing up?

Thanks,
Mike.


#16

indentation, my friend, indentation


#17

This worked for me

def distance_from_zero(a):
if type(a) == int or type(a) == float:
return abs(a)
else:
return 'Nope'

Correct indentation needs to be applied.


#18

You need to put ":" after "if" sentence.

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


#20