0 out of 464 challenges solved
Write a Python function `sum_digits(n)` that calculates the sum of the digits of a given non-negative integer `n`. #### Example Usage: ```python [main.nopy] print(sum_digits(345)) # Output: 12 print(sum_digits(12)) # Output: 3 print(sum_digits(97)) # Output: 16 ``` #### Constraints: - The input `n` will always be a non-negative integer. - Avoid using loops; recursion is required for this challenge.
def sum_digits(n): """ Calculate the sum of the digits of a non-negative integer using recursion. Args: n (int): A non-negative integer. Returns: int: The sum of the digits of the input integer. """ # Base case: If n is 0, return 0 # Recursive case: Add the last digit to the sum of the digits of the rest of the number pass # Replace this with your implementation