首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python "int object is not callable“

Python "int object is not callable“
EN

Stack Overflow用户
提问于 2016-04-28 21:03:39
回答 3查看 1K关注 0票数 0

TypeError:“int”对象不可调用

谁知道我该如何修复这个错误?我知道误差在方程式中的某处。谢谢

代码语言:javascript
复制
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")
EN

回答 3

Stack Overflow用户

发布于 2016-04-28 21:07:24

这里的p是您尝试调用的整数:

代码语言:javascript
复制
total = p (1 + (decimal * n))

我认为你想要:

代码语言:javascript
复制
total = p*(1 + (decimal * n))
票数 1
EN

Stack Overflow用户

发布于 2016-04-28 21:08:24

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

代码语言:javascript
复制
total = p (1 + (decimal * n))

但是p是作为上面的一个参数传递的,所以我猜你是在传递一个整数。如果你想做乘法:

代码语言:javascript
复制
total = p * (1 + (decimal * n))
票数 0
EN

Stack Overflow用户

发布于 2019-05-01 23:09:08

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36915549

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档