primeiro commit com exercicios de Exercism realizados até esta data
This commit is contained in:
@@ -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 <= 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"
|
||||
Reference in New Issue
Block a user