If I want to find the sum of the digits of a number, i.e.:
932
14
(9 + 3 + 2)
This might help
def digit_sum(n): num_str = str(n) sum = 0 for i in range(0, len(num_str)): sum += int(num_str[i]) return sum