#Programmer: Sriram Pemmaraju #Date: March 4th 2011 # This function returns a list with all the factors of n. # The factors are in order starting with 1 and ending with n. def factors(n): L = [] for i in range(1, n+1): if n % i == 0: L = L + [i] return L # A positive integer n is perfect if its factors (excluding itself) # sum to n def isPerfect(n): L = factors(n) return sum(L[0:len(L)-1]) == n # This is the main program. It filters numbers that are # perfect and prints out the list print filter(isPerfect, range(10000))