我如何调试'typeerror的代码:'int'对象在python中是不可调用的'错误? [英] How do i debug this code of the 'typeerror: 'int' object is not callable' error in python?

查看:172
本文介绍了我如何调试'typeerror的代码:'int'对象在python中是不可调用的'错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hey guys! I want to write a program that finds the sum of cubed terms. i.e. 1**3 + 2**3 + n**3
I wrote down the following code:
  
    n = input('Give the value of n.')
n = int (n)
s = ((n(n+1))/2)**2
print ('Sum equals =', s)
The output I got:
   
raceback (most recent call last):
  File "/Users/apple/Documents/tryin.py", line 15, in <module>
    s = ((n(n+1))/2)**2
TypeError: 'int' object is not callable
>>>
Would really appreciate some help guys.
:D
And any suggestions on what to practice to be better at coding and stop getting these errors will be of help.
:)
Thanks!





我尝试过:





What I have tried:

Hey guys! I want to write a program that finds the sum of cubed terms. i.e. 1**3 + 2**3 + n**3
I wrote down the following code:
  
    n = input('Give the value of n.')
n = int (n)
s = ((n(n+1))/2)**2
print ('Sum equals =', s)
The output I got:
   
raceback (most recent call last):
  File "/Users/apple/Documents/tryin.py", line 15, in <module>
    s = ((n(n+1))/2)**2
TypeError: 'int' object is not callable
>>>
Would really appreciate some help guys.
:D
And any suggestions on what to practice to be better at coding and stop getting these errors will be of help.
:)
Thanks!

推荐答案

你错过了一个乘法运算符:

You're missing a multiplication operator:
s = ((n * (n + 1)) / 2) ** 2


这篇关于我如何调试'typeerror的代码:'int'对象在python中是不可调用的'错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆