Python Forum

Full Version: getting an error"Line 7: TypeError: 'int' object is not callable"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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()
You have space between range and (num)
thanks for the reply, but that doesn't affect the code, i fixed but i still get the error.
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.
thanks for the reply, this fixed it thank you Ichabod801.