Menu
CoddyTech

Sum of Digits

You get a non-negative integer n. Return the sum of its decimal digits. For example, the digits of 482 are 4, 8 and 2, so the answer is 14.

Function

sumOfDigits(n: integer) → integer
ninteger
the non-negative integer whose digits you add
Returnsinteger
the sum of the decimal digits of n

Constraints

  • 0 ≤ n ≤ 231-1

Examples

Input
n = 9045
Output
18
Explanation
The digits of 9045 are 9, 0, 4 and 5, and 9 + 0 + 4 + 5 = 18. The zero adds nothing but still counts as a digit.

lock icon+15 hidden tests on Submit

Reset code
def sumOfDigits(n):
    # Write code here
Test cases

Case 1

Case 2

Input

n = 9045

Expected

18