19/19


#1

def distance_from_zero(n):
return type(n) ==int or type(n) == float
print distance_from_zero(15)
print distance_from_zero(15.2)
print distance_from_zero("35")
print("\n")
print max(15,16,17,18)
print min(15,16,17,18)
print("\n")

print abs(15)
print abs(-15)

its return is true and not ten how do I fix this?


#2

Well... The issue here is that you are not using the function parameter anywhere in your function.

TRY:

def distance_from_zero(number):
    try:
        return abs(number)
    except TypeError as error:
        print("You failed to enter a number: %s" % error)

EDIT:

I meant you never used the parameter to work on, you did use it as a comparative.

EDIT:

@sarahbailey3

Try this instead,

def distance_from_zero(p):
    if type(p) in [int,float]:
       return abs(p)
    else:
       return("Nope")

#3

it still says Your function seems to fail on input True when it returned '1' instead of 'Nope'


#4

This is what I put in and it worked.
Just don't copy and paste it since you wouldn't learn anything from doing that

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

#5

If you want to use what Zeziba said do this:

def distance_from_zero(p):
if type(p) in [int,float]:
   return abs(p)
else:
   return "Nope"

#6

Try this mate

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


#7

I tried your code just to see what would happen i tried your code and i still get a name error


#8

It's more simple than that:
def distance_from_zero(n):
if type(n) == int or type(n) == float:
return abs(n)
else:
return "Nope"
print distance_from_zero(14)
print distance_from_zero(-14.5)

Trying to use a Python Shell on your own computer when the things goes wrong.
You going to learn more and the Python Shell give more answers than codec.


#9

that helped me i was returning abs but no parameter


#10

This worked for me too, but why does it print out "None" instead of "Nope" in the result screen? Am I forgetting to do something with my codes?