本文介绍了TypeError:"float"对象不可调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在以下等式中使用数组中的值:

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

这可能很简单,但我不太清楚.任何帮助将是非常感激.预先感谢

this is probably something simple but I can't quite figure it out. Any help would begreatly appreciated. Thanks in advance

推荐答案

缺少运算符,可能是*:

-3.7 need_something_here (prof[x])

出现是不可调用"是因为括号-以及缺少将括号转换为优先运算符的运算符-使Python尝试 call -3.7(浮点数)作为函数的结果,这是不允许的.

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]


如Legolas所指出,还有其他事情可能需要解决:


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 --^

这篇关于TypeError:"float"对象不可调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 10:18