Python“int对象不可调用”

时间:2016-04-28 13:03:39

标签: python-3.x

TypeError:'int'对象不可调用

任何人都知道如何解决此错误?我知道错误在总数中的某个方程式中。感谢

decimal = 0 

rate = 0 

principal = 0 

years = 0

def simple(p, r, n,):

    decimal = r / 100
    print("Principal: " + str(p))
    print("Rate: " + str(decimal))
    print("Number of Years: " + str(n))

    total = p (1 + (decimal * n))
    print("Total: " + str(total))

def main():

    principal = int(input("Enter Principal: "))
    rate = float(input("Enter Rate: "))
    years = int(input("Enter Numbers of Years: "))

    simple(principal, rate, years)

main()

print("End of Program")

3 个答案:

答案 0 :(得分:1)

这里p是你试图调用的整数:

total = p (1 + (decimal * n))

我认为你想要:

total = p*(1 + (decimal * n))

答案 1 :(得分:0)

在这一行上,p应该是一个函数,因为它后面紧跟一个括号:

total = p (1 + (decimal * n))

但是p作为上面的参数传递,所以我猜你传递了一个整数。如果你的意思是乘以:

total = p * (1 + (decimal * n))

答案 2 :(得分:0)

您应该先定义p,然后simple(int p,int r,int t),然后total=p*(1+decim

相关问题