21 lines
646 B
Python
21 lines
646 B
Python
def classify(number):
|
|
"""A perfect number equals the sum of its positive divisors.
|
|
|
|
:param number: int a positive integer
|
|
:return: str the classification of the input integer
|
|
"""
|
|
if number <= 0:
|
|
raise ValueError(
|
|
"Classification is only possible for positive integers.")
|
|
aliquot_sum: int = 0
|
|
# find divisors and store them in a list
|
|
for divisor in range(1, (number // 2) + 1):
|
|
if not number % divisor:
|
|
aliquot_sum += divisor
|
|
if aliquot_sum == number:
|
|
return "perfect"
|
|
elif aliquot_sum > number:
|
|
return "abundant"
|
|
else:
|
|
return "deficient"
|