Skip to content

Instantly share code, notes, and snippets.

@Ikhiloya
Created October 25, 2018 22:34
Show Gist options
  • Save Ikhiloya/1969670519fff76c16f22ce22ec15090 to your computer and use it in GitHub Desktop.
Save Ikhiloya/1969670519fff76c16f22ce22ec15090 to your computer and use it in GitHub Desktop.
A simple function that sums the digit of a number
"""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