PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# this code causes an error because variable has the same name as function sum
# calculate checksum from int
inp = int(input('Integer: '))
inp2 = inp
sum = 0
res = ()
while True:
res = divmod(inp, 10)
sum += res[1] # change to sum1
inp = res[0]
if res[0] == 0:
break
print(sum) # change to sum1
# del sum
# alternative code
print(sum(list(map(int,str(inp2)))))
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run