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


#1



https://www.codecademy.com/courses/python-beginner-c7VZg/4/3?curriculum_id=4f89dab3d788890003000096


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)
    else:
        return "Nope"


#2

@olliemarkwell,
Either you use

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

or

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")

#3

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