Positive integer that is equal to sum of its positive divisor excluding the number itself.
Program
n=int(input("enter number"))
sum=0
for i in range(1,n):
if(n%i==0):
sum=sum+i
if(sum==n):
print("number is perfect")
else:
print("number is not perfect")
Output
enter number6
number is perfect
=== Code Execution Successful ===
Example1
Number is 6
Divisor of 6 is
1,2,3
And sum of divisor is
1+2+3=6
Sum of divisor is equal to the number so 6 is perfect number.
Example2
Number is 5
Divisor of 5 is
1
So sum of divisor is not equal to the number so 5 is not perfect number.
0 Comments