Let’s use Python and start with the skill that makes recursion easier to write and debug: **state what the function returns, then trust that a call on a smaller input returns exactly that.**

### One example, two directions

Suppose `sum_to(n)` returns the sum of the integers from `1` through `n`, for any nonnegative integer `n`.

```python
def sum_to(n):
    if n == 0:
        return 0
    return n + sum_to(n - 1)
```

The **base case** answers a small input directly. Here, the sum of zero numbers is `0`. The **recursive case** reduces the problem. If `sum_to(n - 1)` gives you the sum through `n - 1`, adding `n` gives you the sum through `n`. Each call decreases `n` by one, so it eventually reaches `0`.

When you trace `sum_to(3)`, follow the calls down and the return values back up.

```text
Calls:    sum_to(3) → sum_to(2) → sum_to(1) → sum_to(0)
Returns:      6     ←     3     ←     1     ←     0
```

At `sum_to(3)`, the addition waits until `sum_to(2)` returns. That waiting work is what the call stack keeps track of.

### Your first rep

Write `count_digit(n, digit)` to count how often `digit` appears in the decimal representation of a nonnegative integer `n`. For example, `count_digit(7077, 7)` should return `3`, and `count_digit(0, 0)` should return `1`.

Use `n % 10` to get the last digit and `n // 10` to drop it. Before coding, answer these three questions:

1. What should the function return for a one-digit number?
2. What exactly does `count_digit(n // 10, digit)` give you?
3. How does the last digit change that result?

Send your three answers or your code. We’ll trace your solution, then move to recursion where a call makes two smaller calls, as in traversing a tree.