Well I have a little problem. I want to get the sum of all numbers below to 1000000, and who has 4 divisors...
I try, but i have a problem because the GetTheSum(n) function always returns the number "6"...
This is my Code :
DevSolar
71.1k22 gold badges141 silver badges217 bronze badges
asked Jun 6, 2010 at 13:25
user336671
3433 gold badges5 silver badges9 bronze badges
1 Answer 1
The problem seems to be that you return as soon as you find the first number (which is 6).
You have this:
def GetTheSum(n):
k = 0
for d in range(1,n):
if NumberOfDivisors(d) == 4:
k += d
return k
But you have probably meant this:
def GetTheSum(n):
k = 0
for d in range(1,n):
if NumberOfDivisors(d) == 4:
k += d
return k
answered Jun 6, 2010 at 13:54
Alex B
85.5k49 gold badges213 silver badges285 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py