Created
June 27, 2016 08:29
-
-
Save brettfreer/93fb637b3a2deb43ec1c406ef319f192 to your computer and use it in GitHub Desktop.
Return the sum of digits in an integer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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