

def isPerfect(x):
    # returns True if x is a perfect number
    if x == sumFactors(x):
        return True
    else:
        return False

def sumFactors(x):
    # returns the sum of hte factors of x
    total = 0
    for factor in range(1, x):
        if divides(factor, x):
            total += factor
    return total

def divides(a, b):
    # returns True if a divides evenly into b
    if b % a == 0:
        return True
    else:
        return False
    
def main():
    max = input( "Enter the largest number to check: ")
    for num in range(2, max+1):
        if isPerfect(num):
            print num
                        
main()
