Check whether a number is Perfect number or not

In this program, we will check whether a number is a Perfect number or not.

Definition of perfect number: A positive integer number that is equal to the sum of its proper divisors. The smallest perfect number is 6, its divisors are 1, 2, and 3 and their total sum is 6.
Other perfect numbers are 28, 496, 128.

Steps to solve the program
  1. Take a number as input through the user.
  2. Create a variable and assign its value equal to 0.
  3. Use for loop with the range function to find the factors of the given numbers.
  4. Add those factors to the created variable.
  5. If the value of the variable is equal to the number then it is a perfect number.
				
					num = int(input("Enter a number: "))
total = 0

for i in range(1,num):
    if num % i == 0:
        total += i
        
if total == num:
    print("Number is a perfect number")
else:
    print("Number is not a perfect number")
				
			

Output :

				
					Enter a number: 28
Number is a perfect number
				
			

print all Armstrong numbers between 1 to n

print all Perfect numbers between 1 to n

Leave a Comment