Simple python program to check perfect number using while loop. In this program, we can check a number is a perfect number or not using a python programming language.
Perfect Number Definition
A positive integer that is equal to the sum of its proper divisors is called a perfect number. The sum of 1, 2, and 3 equals 6, which is the smallest perfect number.
The numbers 28, 496, and 8,128 are also perfect. Six is a perfect number in and of itself, not because God made everything in six days; rather, the opposite is true. This program is completely about the python program to check perfect number using while loop.
While Loop Definition in Python
A “While” Loop is used to repeat a block of code an unknown number of times until it meets a condition. The while statement allows you to iterate over a statement until a specified expression is false.
The difference between a for loop and a while loop is that in a for loop, the number of iterations to be performed is already known and is used to obtain a specific result, whereas in a while loop, the command runs until a specific condition is met and the statement is proven false.
Python Program to Check Perfect Number Using While Loop
Num = int(input("Enter The Number")) Sum = 0 for i in range(1, Num): if(Num % i == 0): Sum = Sum + i if (Sum == Num): print("It is a Perfect Number") else: print("It is Not a Perfect Number")
Enter The Number 45
It is Not a Perfect Number