Exercise 19 review error Your function seems to fail on input True when it returned '1' instead of 'Nope'



It says that if fails on input True and returns 1 instead of Nope but I can't figure out why it is doing this or what the error message even really means.Thanks in advance for any help.

I expected it return abs or nope

import math
def distance_from_zero(a):
    if type(a) == int or float:
        return abs(a)
        return "Nope"


Either you use

if type(a) in (int,float):


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

And the call the distance_from_zero() function like

print distance_from_zero(2)
print distance_from_zero(2.2)
print distance_from_zero(-7.7)
print distance_from_zero("2")


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