Skip to content

Commit 57f3654

Browse files
Merge pull request #3 from thechangamunda/main
Sum of divisors in python.
2 parents 14bcc85 + ad76db9 commit 57f3654

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

sum-of-divisors.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Python program to find sum of divisors of a number n,
3+
for example:
4+
print(sum_divisors(0))
5+
# 0
6+
print(sum_divisors(3))
7+
# Should sum of 1
8+
# 1
9+
print(sum_divisors(36))
10+
# Should sum of 1+2+3+4+6+9+12+18
11+
# 55
12+
print(sum_divisors(102))
13+
# Should be sum of 2+3+6+17+34+51
14+
# 114
15+
"""
16+
17+
18+
def sum_divisors(n):
19+
sum = 0
20+
x = 1
21+
while x < n:
22+
if n % x == 0:
23+
sum += x
24+
else:
25+
x += 1
26+
27+
return sum
28+
29+
30+

0 commit comments

Comments
 (0)