Answer to Question #303901 in Python for Christine

Question #303901

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!



Please help me, thank you.

1
Expert's answer
2022-02-28T08:30:04-0500
'''
    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!
    Please help me, thank you.
'''
num=0
while(num<=0):
    num = int(input("Enter a number (>0): "))


Sum=0
Div=[]
s=""
for r in range(1,num):
    if(num%r==0):
        Sum = Sum + r
        s = s+str(r)+"+"
        Div.append(r)
print("Divisors are: ",Div)
print("Sum: ",s,"= ",Sum)
if(Sum==num):
    print("The number = ",num,"is a PERFECT Number.")
if(Sum>num):
    print("The number = ",num,"is a ABUNDANT Number.")
if(Sum<num):
    print("The number = ",num,"is a DEFICIENT Number.")




Python Output

Enter a number (>0): 6
Divisors are:  [1, 2, 3]
Sum:  1+2+3+ =  6
The number =  6 is a PERFECT Number.
>>> 

Enter a number (>0): 12
Divisors are:  [1, 2, 3, 4, 6]
Sum:  1+2+3+4+6+ =  16
The number =  12 is a ABUNDANT Number.
>>> 

Divisors are:  [1, 2, 5]
Sum:  1+2+5+ =  8
The number =  10 is a DEFICIENT Number.
>>> 

Enter a number (>0): 20
Divisors are:  [1, 2, 4, 5, 10]
Sum:  1+2+4+5+10+ =  22
The number =  20 is a ABUNDANT Number.
>>> 

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