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.
'''
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.
>>>
Comments
Leave a comment