Digit Sum Calculator

  • Share this:

Code introduction


Compute the sum of the digits of an integer.


Technology Stack : No packages used

Code Type : Function

Code Difficulty : Beginner


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