Python: perfect number

# coding: utf-8 
"" "  
If a positive integer is equal to the sum of all divisors except itself, it is called a complete number. 
For example: 6 is a complete number, * because 6 = 1 + 2 + 3; A complete number is 28 = 14 + 7 + 4 + 2 + 1. 
Find the complete number "" " 

a = [] 

for i in range (1, 1000 ): 
    s = 0
     for j in range (1 , i ):
         if i% j == 0: 
            s + = j
     if i == s: 
        a.append (i) 

print ( " The complete numbers below 1000 are:% s " % a)

 

 

The result after running:

 

Guess you like

Origin www.cnblogs.com/JodieRao/p/12723593.html