1

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 :

http://pastebin.com/bhiDb5fe

DevSolar
71.1k22 gold badges141 silver badges217 bronze badges
asked Jun 6, 2010 at 13:25
0

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.