- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- 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 −

## Example

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")

## Output

The number is a perfect number

## Explanation

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.

- Related Questions & Answers
- 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

Advertisements