Program Returning "1" for no reason


#1



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


Oops, try again. Your function seems to fail on input True when it returned '1' instead of 'Nope'


I expected it to return "Nope".


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


#2

Re-evaluate the syntax of your if statement.
The syntax should be:
if this is that or this is this:


#3

I think using == is more suitable than using is, since it was what was asked in the instructions.

@scriptcoder12213 When you write if type(distance) == int or float, to the computer it means if type(distance) == int or float, so the second half doesn't make sense on its own.

To fix this, you need to explicitly compare the type of the argument to see if it is float.


#4

Yes, using == the correct method, I was referring to the syntax showing that the second half of the if statement was not complete.


#5

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