We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 14bcc85 + ad76db9 commit 57f3654Copy full SHA for 57f3654
sum-of-divisors.py
@@ -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