You can download this code by clicking the button below.
This code is now available for download.
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