Python Forum
getting an error"Line 7: TypeError: 'int' object is not callable"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
getting an error"Line 7: TypeError: 'int' object is not callable"
#1
hello,
i get an error in this program when trying to find the sum of the values in the array.
this is the error "Line 7: TypeError: 'int' object is not callable"

the code should be adding random integers to the array and then find the sum. but it gives me that error.

def test():
    import random
    sum = 0
    num = int(input("How many values to add to the array: "))
    for x in range (num):
        array.append(random.randint(10,99))
    sum = sum(array)
    print (sum)
    return (array)
##############MAIN##############
array = []
test()
Reply
#2
You have space between range and (num)
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
thanks for the reply, but that doesn't affect the code, i fixed but i still get the error.
Reply
#4
On line 3 you assign 0 to sum, making it an integer. It also means that you no longer have access to the sum built-in function.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
thanks for the reply, this fixed it thank you Ichabod801.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  fixing error TypeError: 'float' object is not subscriptable programmingirl 1 1,523 Jan-28-2023, 08:13 PM
Last Post: deanhystad
  SSL Certificate Error when trying to do command-line registration with pypi DeliriousDelight 0 2,696 Dec-06-2018, 09:38 AM
Last Post: DeliriousDelight
  Integer object error Zatoichi 2 3,725 Feb-18-2018, 07:25 AM
Last Post: Zatoichi
  error 'ring' is not a callable object JakeWitten 1 3,052 May-02-2017, 05:09 AM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020