Skip to content

Instantly share code, notes, and snippets.

@igorvanloo
Created July 21, 2021 13:37
Show Gist options
  • Save igorvanloo/e49654f605702cbe16bb6d4d163fa950 to your computer and use it in GitHub Desktop.
Save igorvanloo/e49654f605702cbe16bb6d4d163fa950 to your computer and use it in GitHub Desktop.
Digit sum Function
#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