24 - Write a program in Python to input a number and determine whether the number is a perfect number or not.
Perfect Number
A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself.
n=int(input("Enter the number: "))
sum=0
for i in range(1,n):
if (n%i==0):
sum = sum+i
if(sum==n):
print(n,"is a perfect number")
else:
print(n,"is not a perfect number")
Output:
Enter the number: 6
6 is a perfect number
Enter the number: 25
25 is not a perfect number
No comments:
Post a Comment