开发者

Problem with a Python function

开发者 https://www.devze.com 2023-01-02 05:48 出处:网络
Well I have a little problem. I want to get the sum of all numbers below to 1000000, and who has 4 divisors...

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 ret开发者_开发知识库urns the number "6"...

This is my Code :

http://pastebin.com/bhiDb5fe


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
0

精彩评论

暂无评论...
验证码 换一张
取 消