Python TypeError:“ float”对象不可调用

时间:2019-08-29 14:29:37

标签: python-3.6

运行以下程序时,我得到错误消息:

  

TypeError:“浮动”对象不可调用。

我尝试将AVG更改为列表。

def AVERAGE_EXPENDITURES(Total,Amount,x):
    b = 0
    y = 0
    AMT = 0
    AVG = 0
    for b in range(x):
        AMT += Amount[b]
    for y in range(x):
        AVG += (AMT-Total[y])/(Total[y])*360/(2*math.pi())/y
    return round(AVG,2)

def Plot_Expenditures(x,Category,Amount,Total):
    TryCatch(x)
    Expenditures(Category, Amount, Total, x)
    plot(x,AVERAGE_EXPENDITURES(Total,Amount,x))
    show()

Plot_Expenditures(x,Category,Amount,Total)

我希望它绘制出类别列表的平均支出。

追溯:

Traceback (most recent call last):   File "/home/jacob/Documents/Python Programs/Expenditures.py", line 47, in <module>
    Plot_Expenditures(x,Category,Amount,Total)   File "/home/jacob/Documents/Python Programs/Expenditures.py", line 44, in Plot_Expenditures
    plot(x,AVERAGE_EXPENDITURES(Total,Amount,x))   File "/home/jacob/Documents/Python Programs/Expenditures.py", line 38, in AVERAGE_EXPENDITURES
    AVG += (AMT-Total[y])/(Total[y])*360/(2*math.pi())/y TypeError: 'float' object is not callable

1 个答案:

答案 0 :(得分:0)

不是AVG不能在您的代码中调用,而是math.pi。您正在做math.pi(),但是正在尝试将浮点常量math.pi调用为函数。

替换:

AVG += (AMT-Total[y])/(Total[y])*360/(2*math.pi())/y 

具有:

AVG += (AMT-Total[y])/(Total[y])*360/(2*math.pi)/y