Python BasicsEasy

Perfect number

Detailed guide and Python implementation for the 'Perfect number' problem.

Problem Statement

Easy

Write a function is_perfect(n) that takes a positive integer n and returns True if it is a perfect number, or False otherwise. A perfect number is a number that equals the sum of its proper divisors (all divisors excluding the number itself). For example, 6 = 1 + 2 + 3.

Constraints
  • 1 <= n <= 10^6

Examples

Example 1
Input
n = 6
Output
True
Explanation

The proper divisors of 6 are 1, 2, 3. Their sum is 1 + 2 + 3 = 6.

Example 2
Input
n = 28
Output
True
Explanation

The proper divisors of 28 are 1, 2, 4, 7, 14. Their sum is 1 + 2 + 4 + 7 + 14 = 28.

Example 3
Input
n = 12
Output
False
Explanation

The proper divisors of 12 are 1, 2, 3, 4, 6. Their sum is 16, which is not 12.

Need a Hint?
Consider using Basics-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.