Perfect number program in python

In this example, you will learn to check whether number is perfect number or not based on user input.

What is Perfect Number?

Perfect number, 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.

Example :

#Python Program to Check a Number is a Perfect Number or Not

num = int(input("Enter a number :: "))
sumOfFactors = 0

#Calculating the sum of Factors
for i in range(1,num):
    if num%i == 0:
        sumOfFactors += i;

if sumOfFactors == num:
    print(num ," is Perfect Number")
    print(num ,"is not a Perfect Number")

Output :

Enter a number :: 10
10 is not a Perfect Number

Share your thoughts

Ask anything about this examples