Help me with 19/19, please


#1

I have a problem:
I printed a code:

def distance_from_zero(q):
if type (q) == int or type(q) == float:
print (abs(q))
else:
print ("Nope")

But python doesn`t like this:

Oops, try again.
Your function seems to fail on input -10 when it returned 'None' instead of '10'

Help me, please


#2

not print. return

def distance_from_zero(q):
if type (q) == int or type(q) == float:
print (abs(q))
else:
print ("Nope")


#3

I found that the 'or' boolean did not work, so I split the test into two separate lines.


#4

def distance_from_zero(q):
if type (q) == int:
print (abs(q))
elif type(q) == float:
print (abs(q))
else:
print ("Nope")
Like this?
It doesn`t work too :frowning:


#5

Thank you all! With two separate lines and "return" it works!!!


#6

I have the same problem:
def distance_from_zero(thing):
if type(thing)== float or type(thing) == int:
print (abs(thing))
else:
print"Nope"
distance_from_zero(-10)

I got the follwing result 10 and None and the feedback
Oops, try again.
Your function seems to fail on input -10 when it returned 'None' instead of '10'
Could you tell me, what you corrected in your version?


#7

Hi try that code this line if type(thing)== float or type(thing) == int: should be like that if type(thing)== float or type(thing) == float:
adn then add print before distance_from_zero(-10) so it should be like that

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

print distance_from_zero(-10)

#8
> def distance_from_zero(d):
>     if (type(d) == int) or (type(d) == float):
>         return abs(d);
>     else:
>         return "Nope";

> print distance_from_zero(-10.0)

This is my answer, hope it helps. Try to use brackets, it always helps, and also I printed the function with a value in it, it's very helpful.