Answer to Question #303061 in Python for Loki

Question #303061

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

1
Expert's answer
2022-02-28T01:04:32-0500
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))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS