Created
October 25, 2018 22:34
-
-
Save Ikhiloya/1969670519fff76c16f22ce22ec15090 to your computer and use it in GitHub Desktop.
A simple function that sums the digit of a number
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
"""A simple function that sums the digit of a number""" | |
# x could be any number such as 1234, the function will result in (1 + 2 + 3 + 4) = 10 | |
def digit_sum(x): | |
string_val = str(x) | |
sum = 0 | |
for i in string_val: | |
sum += int(i) | |
return sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment