Input number and check perfect number or not using while loop in Python
while Loop - Question 8
In this question, we will see how to input a number and check if it is a perfect number or not in Python programming using while loop. To know more about while loop click on the while loop lesson.
Q8) Write a program in Python to input a number and check if it is a perfect number or not using while loop.
A Perfect number is a number, whose sum of the factors excluding the given number itself is equal to the given number.
Example: Sum of factors of 6 excluding 6 is 1+2+3 which is equal to 6, so 6 is a perfect number.
n=int(input('Enter a number '))
sf=sf+i # sum of factors
print('Not Perfect Number')
Enter a number 28 Perfect Number