Jump to content

int object is not callable error

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Guest

Guest

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,414 posts
I am trying to solve problem 21 in project Euler with Python.
Problem 21 - Project Euler
I wrote this bit of code as a solution:
def d(n):
    i=2
    if (n==1):
        return 0
    factors=[1]
    while (i*i<=n):
        if (n%i==0):
            if (i!=n/i):
                factors+=[i,n/i]
            else:
                factors+=[i]
        i+=1
    return sum(factors)

a=2
sum=0
b=0
while (a<10000):
    b=d(a)
    if (d(b)==a and a!=b):
        sum+=a+b
    a+=1

print sum
I receive this error when running the code:
Traceback (most recent call last):
  File "test.py", line 19, in <module>
    b=d(a)
  File "test.py", line 13, in d
    return sum(factors)
TypeError: 'int' object is not callable
I used Google, and evidently this error happens when calling numbers functions (ex 4() )
Obviously, d is not a number, and even renaming the function does not fix my problem. If you know what's going on, please reply.
Root Beer == System Administrator's Beer
Download the new operating system programming kit! (some assembly required)

#2
Guest

Guest

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,414 posts
Never mind, I just realized the sum variable is conflicting with the sum function. Maybe I should get some sleep :p
Root Beer == System Administrator's Beer
Download the new operating system programming kit! (some assembly required)