19 - What is incorrect about this code?


#1



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


My code returns 1 instead of returning "Nope" with an input of "True."


I expect the code the return "Nope" because type(True) is neither an integer or a float.


Replace this line with your code. 
def distance_from_zero(x):
    if type(x) == int or float:
        return abs(x)
    else:
        return "Nope"


#2

I'm not really familiar with python but from what i see you almost have it except you have to set type for your or as well like this:

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

hope this helps


#3

The problem is here, you have to make it clear you're referring to type(x) so you would write,

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

Should work after correcting that. :grin:


#4

Thank you cfecteau1 and bandit! Really helped. Thanks a lot, and have a great day!


#5

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