Program Returning "1" for no reason


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


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


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.


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


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