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 sumI 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 callableI 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.


Sign In
Create Account


Back to top









