Recursive Digit Sum

Lab Python Intermediate 20 points

Write a recursive digit_sum(n) for a non-negative integer.

Input

One integer.

Output

The sum of its digits.

Example

Input

12345

Output

15
Sample input available Sample output available
Editor
Python

Hints

Last digit + digit_sum of the rest.

Solution explanation

Peeling off one digit per call shrinks the problem each time.

Show solution
def digit_sum(n):
    if n < 10:
        return n
    return n % 10 + digit_sum(n // 10)


print(digit_sum(int(input())))
Output
Answer
HOME LEARN COMMUNITY DASHBOARD