Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How do I debug this code of the 'TypeError: 'int' object is not callable' error in Python?

    • 0
    • 0
    • 0
    • 7
    • 0
    • 0
    • 0
    • 5.38k
    Answer it

    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


    >>>
    I 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!

 7 Answer(s)

  • when you get a error like that: "type integer is not callable", it's prabbly a syntax error / typo:

    the syntax for calling a function in Python is to put parens after it:

    fun()

    so look and see if you have put parens after something that is not a function -- and indeed you have:

    (note this UI sucks! I have to write this in a modal dialog, so I can't see the original question!)

    I think you have code like:

    n(1 + n)

    look for the n(...) -- that is math notation for multiply, but it's python notation for call the function "n" -- it should be:

    n * (1 + n)

  • You have to redefined your "sum" function to be an integer data type. So it is rightly telling you that an integer is not something you can pass a range.To fix this, restart your interpreter.Then all is okay.like this n = input('Give the value of n.') n = int (n) s = (((n+1))/2)**2 print ('Sum equals =', s)

  • You have to redefined your "sum" function to be an integer data type. So it is rightly telling you that an integer is not something you can pass a range.To fix this, restart your interpreter.Then all is okay

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: