Summing Digits of an Integer

  • Share this:

Code introduction


Calculate the sum of all digits of an integer.


Technology Stack : Built-in Python libraries

Code Type : Function

Code Difficulty :


                
                    
def sum_digits(n):
    total = 0
    while n > 0:
        total += n % 10
        n //= 10
    return total