Write a program to print all perfect numbers between 1 to 100

```
#Finding Perfect Numbers
#A number is perfect if it is equal to the sum of its proper divisors (i.e., not #counting itself). For example, 6 = 1 + 2 + 3 and 28 = 1 + 2 + 4 + 7 + 14 are the #first two perfect numbers.
def isPerfectNum(n):
sum = 0
for i in range(1, n):
if (n % i == 0):
sum = sum + i
if (sum == n):
return True
else:
return False
#main
for n in range(101): #change the value to 1001 and see the difference
if (isPerfectNum(n)):
print(n, " is a perfect number")
#EOProgram
```

Advertisements