- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to Check if a Number is a Perfect Number
A number is said to be a Perfect Number when that is equal to the sum of all its positive divisors except itself. When it is required to check if a number is a perfect number, a simple ‘for’ loop can be used.
Below is the demonstration of the same −
n = 6 my_sum = 0 for i in range(1, n): if(n % i == 0): my_sum = my_sum + i if (my_sum == n): print("The number is a perfect number") else: print("The number is not a perfect number")
The number is a perfect number
The value for ‘n’ is specified.
The sum is initialized to 0.
The number is iterated over, and the sum is incremented.
If this sum is equal to the previously defined ‘n’, it is considered a perfect number.
Relevant messages are displayed on the console.
- Golang Program to Check if a Number is a Perfect Number
- Python Program to Check if a Number is a Strong Number
- Check if given number is perfect square in Python
- Python program to check if the given number is a Disarium Number
- Python Program for How to check if a given number is a Fibonacci number?
- How to check if a given number is a Fibonacci number in Python Program ?
- C Program to check Plus Perfect Number
- Python program to check if a number is Prime or not
- Python program to check if a given string is number Palindrome
- Python program to check if the given number is Happy Number
- Check if a number is perfect square without finding square root in C++
- C program to find if the given number is perfect number or not
- Java Program for check if a given number is Fibonacci number?
- Python Program to Check if a Number is Positive, Negative or 0
- Java Program to check if a string is a valid number