# Finds all perfect 3-digit numbers.
#
# Written by Eric Martin for COMP9021


print('The solutions are:')
for i in range(100, 1000):
    sum_of_divisors = 1
    for j in range(2, i // 2 + 1):
        if i % j == 0:
            sum_of_divisors += j
    if i == sum_of_divisors:
        print('{:} is a solution.'.format(i))

Resource created Monday 17 August 2015, 09:31:54 AM.

file: question_2.py


Back to top

COMP9021 15s2 (Principles of Programming) is powered by WebCMS3
CRICOS Provider No. 00098G