Skip to content

Instantly share code, notes, and snippets.

@brettfreer
Created June 27, 2016 08:29
Show Gist options
  • Save brettfreer/93fb637b3a2deb43ec1c406ef319f192 to your computer and use it in GitHub Desktop.
Save brettfreer/93fb637b3a2deb43ec1c406ef319f192 to your computer and use it in GitHub Desktop.
Return the sum of digits in an integer
def sum_of_digits(n):
s = 0
while n > 0:
s += n % 10
n /= 10
return s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment