Python Forum
getting an error"Line 7: TypeError: 'int' object is not callable" - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: getting an error"Line 7: TypeError: 'int' object is not callable" (/thread-17215.html)



getting an error"Line 7: TypeError: 'int' object is not callable" - JTNA - Apr-02-2019

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()



RE: getting an error"Line 7: TypeError: 'int' object is not callable" - perfringo - Apr-02-2019

You have space between range and (num)


RE: getting an error"Line 7: TypeError: 'int' object is not callable" - JTNA - Apr-02-2019

thanks for the reply, but that doesn't affect the code, i fixed but i still get the error.


RE: getting an error"Line 7: TypeError: 'int' object is not callable" - ichabod801 - Apr-02-2019

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.


RE: getting an error"Line 7: TypeError: 'int' object is not callable" - JTNA - Apr-03-2019

thanks for the reply, this fixed it thank you Ichabod801.