Perfect Number Check
Test whether a positive integer equals its proper-divisor sum. A lesson on excluding the number itself, accumulating factors, and perfect-number boundaries.
1# Take number2num = int(input("Enter a number: "))34# Find sum of proper divisors5divisor_sum = 06for i in range(1, num):7 if num % i == 0:8 divisor_sum += i910# Check perfect number11if num > 0 and divisor_sum == num:12 print("Perfect number")13else:14 print("Not a perfect number")
Output
Enter a number: 6 Perfect number Enter a number: 10 Not a perfect number
In this one
- Find proper divisors
- Exclude the number itself
- Require a positive domain
How it works
- 1
Scan divisors from one below num.
- 2
Add candidates with remainder zero.
- 3
Require positive num and a matching divisor sum.
Edge cases
Is one perfect?
Is one perfect?
No. Its proper-divisor sum is zero.
Is zero perfect?
Is zero perfect?
No. The final decision needs a positive-domain guard rather than accepting an empty sum.
What's going on
A proper divisor is a positive factor smaller than the number. range(1, num) deliberately excludes num while the remainder test selects its divisors.
For six, the selected factors one, two, and three sum to six. One has no proper positive divisors, so its total is zero and it fails. The mathematical domain is positive integers; zero must not pass just because an empty total is zero.
Is one perfect? No. Its proper-divisor sum is zero.
Is zero perfect? No. The final decision needs a positive-domain guard rather than accepting an empty sum.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Which factor is excluded?
Pick an answer to check it.
Question 2
Is one perfect?
Pick an answer to check it.
Questions people ask
Is one perfect?
No. Its proper-divisor sum is zero.
Is zero perfect?
No. The final decision needs a positive-domain guard rather than accepting an empty sum.
Which factor is excluded?
The number itself.
๐Related Content
- ๐
Phase 2 - Learn Concepts
Review Phase 2 concepts and explanations
- ๐
Phase 2 - Quiz
Test your Phase 2 understanding with quiz questions
- ๐ป
Phase 2 - All Practice Problems
Explore all practice problems for Phase 2
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum