PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def sum_divisors(n):
sum = 0
# Return the sum of all divisors on n,
# not including n.
index = 0
if n == 0: #I edited the code a little bit
sum += n
else:
while index < n // 2:
index += 1
if n % index == 0:
sum += index
return sum
print(sum_divisors(0))
#0
print(sum_divisors(3)) # Should sum of 1
#1
print(sum_divisors(36)) # Should sum 1+2+3+4+6+9+12+18,
#55
print(sum_divisors(102)) # Should be sum
# 2+3+6+17+34+51,
# 114
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run