Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions solutions/python/perfect-numbers/1/perfect_numbers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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 < 1:
raise ValueError("Classification is only possible for positive integers.")
copy_num = number
aliquot = 0
for i in range(1, copy_num):
if copy_num % i == 0:
aliquot += i
if aliquot == copy_num:
return "perfect"
elif aliquot < copy_num:
return ("deficient")
else:
return "abundant"
#classify(15)