You are here:Home » python » Sum of digits

Sum of digits


Here is a python function to find the sum of digits of a given number. Make sure that your input to the function is an integer
def sum_digits(n):
    s = 0
    while n:
        s += n % 10
        n /= 10
    return s