I have 3 functions working together, but I only have abundant returned every single time, I don't know what is wrong

def sumDivisors(n):
    total = 0
    for counter in range(1, n):
        if (isDivisor(n, counter)):
            total += counter
        return total


def checkForPerfect(n):
    total = sumDivisors
    if (total == n):
        return 'Perfect'
    elif (total < n):
        return 'Deficient'
    else:
        return 'Abundant'
    

    
        
        
def isDivisor(a, b):
    if (a%b) == 0:
        return True
    return False

line 10 should be total = sumDivisors(n) . Also you can speed this up by adding total += counter + n/counter when counter < n/counter and total += counter when counter == n/counter .

adding the (n) does nothing, I get the same results

You must unindent line 6 :)

LOL, it's always the simplest answers, I can't believe I didnt see that -.- THANKS

One more question, I'm also getting wrong output from the following, trying to find prime or composite numbers:

def isPrime(n):
    if (n==2):
        return True
    for counter in range(3,n):
        if n % counter == 0:
            return False
        return True

for the output:

for n in range (start,end+1):
        prime = isPrime(n)
if (n==1):
        print "%-11s" %'Neither',
        
    elif prime:
        print "%-11s" %'Prime',
    else:
        print "%-11s" %'Composite',

Your function isPrime should read

def isPrime(n):
    if (n==2):
        return True
    for counter in range(2,n):
        if n % counter == 0:
            return False
    return True

Also it's very inefficient.

yeah I know its inefficient, but thats the way the prof. want's it :icon_confused:
Thanks for the correction, I keep overseeing mundane details

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.