Perfect number
A perfect number is a positive integer that is equal to the sum of its proper divisors. The smallest perfect number is 6, which is the sum of 1, 2, and 3.
Logic
To check if the number is perfect or not we have to run one loop from 1 to N and sum all the numbers between 1 to N, if the sum is equal to N then it is a perfect number.
Program
# Take input from user num = int(input("Enter any number : ")) sum = 0 # Calculate sum of all proper divisors for i in range(1, num): if num % i == 0: sum += i # Empty print statement for new line print() # Check whether the sum of divisors is equal to num if sum == num: print(num, "is PERFECT NUMBER") else: print(num, "is NOT PERFECT NUMBER")
Output
Enter any number : 5
5 is NOT PERFECT NUMBER