Lecture Notes on 01 July 2013
# Tests if a given number is perfect or not
def main():
num = eval (input ("Enter number: "))
sum_divisors = 0
limit = num // 2
for i in range (1, limit + 1):
if (num % i == 0):
sum_divisors = sum_divisors + i
if (num == sum_divisors):
print (num, "is a perfect number")
else:
print (num, "is not a perfect number")
main()
# Prints all perfect numbers less than 10,000
def main():
for j in range (1, 10001):
sum_divisors = 0
limit = j // 2
for i in range (1, limit + 1):
if (j % i == 0):
sum_divisors = sum_divisors + i
if (j == sum_divisors):
print (j)
main()