19/19 - SyntaxError


This is my code:

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

And I keep getting this error message..

File "python", line 2
if type(thing) == int or type(thing)
SyntaxError: invalid syntax

What am I doing wrong?


I would personally not type check like that it just leads to issues as you can see. Also I would put in error handling for any input that is not valid as follows.

Do the Following:

def distance_from_zero(item):
        return abs(item)
    except TypeError as error:
        print("You have had an error: %s" % error)


The problem is the evaluation in if:
if type(thing)==int(thing) or type(thing)==float(thing)

you cant compare only with int or float