def digit_sum(n):
total = 0
numberStringfied = str(n)
listNumbers = list(numberStringfied)
for n in listNumbers:
total += int(n)
return total
Function that takes a positive integer n as input and returns the sum of all that number's digits.
For example: digit_sum(1234) should return 10 which is 1 + 2 + 3 + 4.
For example: digit_sum(1234) should return 10 which is 1 + 2 + 3 + 4.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.