Created
July 21, 2021 13:37
-
-
Save igorvanloo/e49654f605702cbe16bb6d4d163fa950 to your computer and use it in GitHub Desktop.
Digit sum Function
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
#x % 10 will be the first digit, then we x // 10 to remove it and repeat | |
def sum_digits(x): | |
totalsum = 0 | |
while x != 0: | |
totalsum += x % 10 | |
x = x // 10 | |
return totalsum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment