Perfect Number Code in Python
What is Perfect Number?
Perfect number is a positive integer that is equal to the sum of its proper divisors. In this program we will be checking whether the given number is perfect or not using for loop. Initially we will be finding the proper divisors of the number and then we will find the sum of the divisors. If the sum is equal to the number, then the number is perfect.
- Example n=14
- Proper divisors of 14 are 1,2,7
- Sum of the divisors is 10
- 14 is not a perfect number
- Input n
- Initialize sum=0
- Iterate through loop and find the divisors of n and add the divisors to the sum
- Check whether the sum is equal to n
- If equal display “Perfect number”
- else display “Not perfect number”