TypeError: 'float' object is not callable
Sebastian Wright
I am trying to use values from an array in the following equation:
for x in range(len(prof)): PB = 2.25 * (1 - math.pow(math.e, (-3.7(prof[x])/2.25))) * (math.e, (0/2.25)))When I run I receive the following error:
Traceback (most recent call last): File "C:/Users/cwpapine/Desktop/1mPro_Chlavg", line 240, in <module> PB = float(2.25 * (1 - math.pow(math.e, (-3.7(prof[x])/2.25))) * (math.e, (0/2.25)))
TypeError: 'float' object is not callablethis is probably something simple but I can't quite figure it out. Any help would be greatly appreciated. Thanks in advance
24 Answers
There is an operator missing, likely a *:
-3.7 need_something_here (prof[x])The "is not callable" occurs because the parenthesis -- and lack of operator which would have switched the parenthesis into precedence operators -- make Python try to call the result of -3.7 (a float) as a function, which is not allowed.
The parenthesis are also not needed in this case, the following may be sufficient/correct:
-3.7 * prof[x]As Legolas points out, there are other things which may need to be addressed:
2.25 * (1 - math.pow(math.e, (-3.7(prof[x])/2.25))) * (math.e, (0/2.25))) ^-- op missing extra parenthesis --^ valid but questionable float*tuple --^ expression yields 0.0 always --^ 1 The problem is with -3.7(prof[x]), which looks like a function call (note the parens). Just use a * like this -3.7*prof[x].
You have forgotten a * between -3.7 and (prof[x]).
Thus:
for x in range(len(prof)): PB = 2.25 * (1 - math.pow(math.e, (-3.7 * (prof[x])/2.25))) * (math.e, (0/2.25)))Also, there seems to be missing an ( as I count 6 times ( and 7 times ), and I think (math.e, (0/2.25)) is missing a function call (probably math.pow, but thats just a wild guess).
While this may not be an answer to this question in particular, another reason you could get this error is if you have defined "range" as a variable.
range = 0
for x in range(len(array)):
#will give an error, because it's trying to multiply "range" with "(len(array))"The solution would be to rename your variable to a synonym (period) or append something to it (range1, range_a)