TypeError: 'float' object is not callable
Question:
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 callable
What is the cause, and how can the problem be resolved?
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 --^
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).
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]
.
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)
The question has been answered but for others, the reason for the same error might be highly possible due to the following reason:
Sometimes, when you use a variable name same as one of the inbuilt functions and when you try to call that inbuilt function later on, its gonna give you a type error.
For example, somewhere in your code you define a variable as:
sum = 0
Maybe to use it as an accumulator variable in global dataframe.
Now, later when you’re defining a function in which you want to call the inbuilt function sum() , its gonna give an type error as you have over-written an in-built function name.
That’s why, you should avoid the use in-built function names like str, range, sum, etc.. as one of the variable names in your code.
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 callable
What is the cause, and how can the problem be resolved?
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 --^
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).
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]
.
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)
The question has been answered but for others, the reason for the same error might be highly possible due to the following reason:
Sometimes, when you use a variable name same as one of the inbuilt functions and when you try to call that inbuilt function later on, its gonna give you a type error.
For example, somewhere in your code you define a variable as:
sum = 0
Maybe to use it as an accumulator variable in global dataframe.
Now, later when you’re defining a function in which you want to call the inbuilt function sum() , its gonna give an type error as you have over-written an in-built function name.
That’s why, you should avoid the use in-built function names like str, range, sum, etc.. as one of the variable names in your code.