forked from fenyx-it-academy/Class5-Python-Module-Week3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq1.py
More file actions
19 lines (15 loc) · 732 Bytes
/
q1.py
File metadata and controls
19 lines (15 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# ## 1-perfect_number.py
# Perfect number: Perfect number is a positive integer that is equal to the sum of its proper divisors.
# The smallest perfect number is `6`, which is the sum of `1`, `2`, and `3`.
# Some other perfect numbers are `28(1+2+4+7+14=28)`, `496` and `8128`.
# Write a function that finds perfect numbers between `1` and `1000`.
# Check perfect numbers between `1` and `1000` and find the sum of the perfect numbers using reduce and filter functions. <br />
def perfect_number(x):
summ=0
for i in range(1,x):
if x%i==0:
summ+=i
if summ==x:
return True
from functools import reduce
print(reduce(lambda a,b:a+b,(list(filter(lambda x: perfect_number(x),range(1,1000))))))