Skip to content

Commit 0d4d062

Browse files
committed
Checking whether the number is a Perfect Number
1 parent 2c785b1 commit 0d4d062

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Programs/P58_PerfectNumber.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Author: OMKAR PATHAK
2+
3+
# Wikipedia : In number theory, a perfect number is a positive integer that is equal to the sum of
4+
# its proper positive divisors, that is, the sum of its positive divisors excluding the number itself
5+
# (also known as its aliquot sum). Equivalently, a perfect number is a number that is half the sum of all
6+
# of its positive divisors (including itself).
7+
# Example : The first perfect number is 6, because 1, 2, and 3 are its proper positive divisors,
8+
# and 1 + 2 + 3 = 6. Equivalently, the number 6 is equal to half the sum of all its positive divisors:
9+
# ( 1 + 2 + 3 + 6 ) / 2 = 6. The next perfect number is 28 = 1 + 2 + 4 + 7 + 14. This is followed by the
10+
# perfect numbers 496 and 8128.
11+
12+
def perfectNumber(number):
13+
sum = 0
14+
for x in range(1, number):
15+
if number % x == 0:
16+
sum += x
17+
return sum == number
18+
19+
if __name__ == '__main__':
20+
print(perfectNumber(6)) # True
21+
print(perfectNumber(3)) # False

0 commit comments

Comments
 (0)