;

# Python Program to Find the Perfect Number between 1 to 1000

###### Tutorialsrack 25/04/2020 Python

In this Python program, we will learn how to find or print the perfect number between 1 to 1000 or between a specific range.

## What is a Perfect Number?

A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself.

For Example, 6 has divisors 1, 2 and 3 (excluding itself), and 1 + 2 + 3 = 6, so 6 is a perfect number.

The sum of divisors of a number, excluding the number itself, is called its aliquot sum, so a perfect number is one that is equal to its aliquot sum. In other words, a perfect number is a number that is half the sum of all of its positive divisors including itself

I.e. σ1(n) = 2n

For Example, 28 is perfect as 1 + 2 + 4 + 7 + 14 + 28 = 56 = 2 × 28

Here is the code of the program to find or print the perfect number between 1 to 1000 or between a specific range.

##### Python Program to Find the Perfect Number between 1 to 1000 or Between a Specific Range
``````# Python Program to Find the Perfect Number between 1 to 1000 or Between a Specific Range

# Take the input from the user
MinValue = int(input("Enter any Minimum Value: "))
MaxValue = int(input("Enter any Maximum Value: "))

# initialise sum
print("\nPerfect Number Between {0} to {1}".format(MinValue,MaxValue))
# Checking the Perfect Number
for Number in range(MinValue, MaxValue - 1):
Sum = 0
for n in range(1, Number - 1):
if(Number % n == 0):
Sum = Sum + n
# display the result
if(Sum == Number):
print("%d " %Number)
``````
##### Output

Enter any Minimum Value: 1

Enter any Maximum Value: 1000

Perfect Number Between 1 to 1000

28

496