Write a function to calculate the sum of digits of a number


Topic: Write a function to calculate the sum of digits of a number

Solution

def sum_of_digits(num):
    sum = 0
    while(num > 0):
        sum += num % 10
        num = num // 10
    return sum



List all Python Programs