Click here to Skip to main content
15,915,160 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
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:

C#
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!
Posted
Comments
OriginalGriff 15-Feb-16 11:53am    
Do not repost the same question - use the "Improve question" widget to edit the existign and improve it.
I deleted the "spare".

1 solution

You're missing a multiplication operator:
Python
s = ((n * (n + 1)) / 2) ** 2
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-Feb-16 17:56pm    
5ed, but probably it may need some explanation.
n(...) can be considered as a function or type cast which can be "called", which is not. The error message is somewhat confusing: instead of saying "n is not callable", it says "int is not callable", because n was type-cast to int, so the interpreter can see that this is int.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900