Skip to content

Instantly share code, notes, and snippets.

@m4hi2
Created May 4, 2022 06:05
Show Gist options
  • Save m4hi2/b9c5f495346b31ed408d19922273e391 to your computer and use it in GitHub Desktop.
Save m4hi2/b9c5f495346b31ed408d19922273e391 to your computer and use it in GitHub Desktop.
def get_sum_of_individual_digits(n: int, total: int = 0) -> int:
if n == 0:
# print(total)
return total
digit = n % 10
total = total + digit
return get_sum_of_individual_digits(n // 10, total)
print(get_sum_of_individual_digits(200))
print(get_sum_of_individual_digits(112))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment