Calculate Sum Get User Input Patterns Program Find Area of CircleFind Area of Rectangle Perimeter of Rectangle Find Even and Odd Numbers Find Sum of Digit in Python Find Factorial in PythonPrint Fibonacci Series Check Armstrong Number Reverse a Number Check Palindrome Number Swap Two Numbers Matrix MultiplicationFind Perfect NumberAdd Two Matrix in Python Find Sum of Squares Find Sum of Cubes Find URL in String
Find Largest in List Find Duplicate in List Check Alphabet Remove Duplicate Elements from List Reverse List Elements Find Element in Python List Interchange first and last element in List Find Even Numbers in List Find Length of a List Find Sum of list Elements Find Elements in List Get the product of List elements Interchange List Elements Find Smallest Elements in List Find Max Value in a List
A perfect number is a number that is equal to the sum of its divisor, excluding the number itself, i.e. if we sum up all the divisors of a number, excluding the number itself will be equal to the number. For example, 6 is a perfect number because its divisors are 1, 2, and 3, and the sum of these is 1 + 2 + 3 = 6. Let's see a python program to find the perfect number.
Step 1: Create two variables number and div_sum, and initialize with the number and 0, respectively.
Step 2: Start a loop and set a condition from 1 to number.
Step 3: Add an if condition to check whether the divisor is successful.
Step 4: Add Divisor to the div_sum variable.
Step 5: Add an if condition to check whether the number and div_sum both are the same.
Step 6: Print It is a Perfect Number if both are the same, It is not Perfect Number otherwise.
*number = 6 in our program case.
Let's see its implementation in Python language.
"""
Python Program to Check Perfect Number
"""
# Take a number
number = 6
div_sum = 0
for i in range(1,number):
if number%i==0:
div_sum += i
if div_sum == number:
print("It is a Perfect Number")
else:
print("It is not Perfect Number")
Output:
It is a Perfect Number