59. Python Program to find the given number is Perfect number or Not.
How does this program work?
- In this program you are going to learn about to check if a number is Perfect number or not using Python.
- A perfect number is a number if it is equal to the sum of its factors, which means original number is equal to sum of all its factors except the number itself.
- If sum is equal to the original number, then that number is perfect number else the number is not a perfect number.
Here is the code
n = int(input(" Please Enter any Number: "))
a = 0
for i in range(1, n):
if(n % i == 0):
a += i
if (a == n):
print(n," is a Perfect Number")
else:
print(n," is not a Perfect Number")