Create a Python script which will accept a positive integer and will
determine the input number if PERFECT, ABUNDANT, DEFICIENT.
PERFECT – if the sum of the divisors of the number except the number itself is
equal to the number.
E.g. 6 = 1, 2, 3, 6 1 + 2+ 3 = 6
ABUNDANT – if the sum of the divisors of the number except the number itself
is greater than the number.
E.g. 12 = 1, 2, 3, 4, 6, 12 1 + 2 + 3 + 4 + 6 = 16
DEFICIENT – if the sum of the divisors of the number except the number itself is
less than the number.
E.g. 10 = 1, 2, 5, 10 1 + 2 + 5 = 8
Sample Output:
Input a Positive Integer : 20
20 is ABUNDANT!
need the input code
def type_of_num(num):
factors = []
for i in range(1, num + 1):
if num % i == 0:
if i != num:
factors.append(i)
if sum(factors) == num:
type_num = "Perfect"
elif sum(factors) > num:
type_num = "Abundant"
else:
type_num = "Deficient"
return type_num, factors
print(type_of_num(32))
Comments
Leave a comment