6=1+2+3

28=1+2+4+7+14

# 程序

#the programe is judging whether the number is perfect
#the perfect number is number that the sum of its factor equals itself
#like 6=1+2+3,28=1+2+4+7=14

topNum=raw_input("Please enter the upper number of the range: \n")
topNum=int(topNum)
theNum=2

while theNum<=topNum:
#sum up all the factor
divisor=1
sumofDivisors=0
#judge whether it is the factors of theNum
while divisor<theNum:
if theNum%divisor==0:
sumofDivisors=sumofDivisors+divisor
divisor=divisor+1
if theNum==sumofDivisors:
print theNum,"is perfect"
theNum+=1


Written on January 13, 2013