Float object is not callable


#1

Hi
I am on Functions -19/19, trying out the exercise in this page.

This the function I wrote:

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

I see the error as:
Oops, try again. It looks like you have a TypeError. Make sure your function should only take one input. (Or check the error message for more info.) - 'float' object is not callable

I tried changing this line from: if type(sth) == int or type(sth) == float:
to 1: if type(sth) == int(sth) or type(sth) == float(sth):
2: if type(sth) == "int" or type(sth) == "float":

none of them worked. Also abs(1.2344) fails too.

Any help is appreciated.

Thanks


#2

Hmmm... I refreshed the screen (Control+F5) and then, it started working...
This thread can be closed.


#3

def distance_from_zero(dist):
if type(dist)==int:
dist=abs(dist)
return dist
elif type(dist)==float:
dist=abs(dist)
return dist
else:
return "Nope"