Adding up the digits
Write code · Basic · §1.1 Digits
Complete the function solution, which returns the sum of the digits of the non-negative integer n.
Function
solution(n)
Constraints
nis an integer from 0 to 1,000,000,000,000,000,000 (10¹⁸).
Examples
| n | result |
|---|---|
123 | 6 |
9081 | 18 |
Starter code
def solution(n):
answer = 0
return answerSolve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.