Advent of Python 2026Day 2 is out →

    Day 15Count the Baubles

    Ho ho ho! Day 2 of 25. Another present to unwrap. Solve it on your own, no hints and no AI!

    A tree is drawn as a string. Small baubles are the letter o and big baubles are the capital letter O. Everything else is branches, tinsel or spaces.

    Write count_baubles(tree) that returns how many baubles there are, small and big together.

    Examples

    Example 1
    >>> count_baubles('*o**O*')
    2
    Example 2
    >>> count_baubles('****')
    0

    Good to know

    • A tree with no baubles has 0.

    Check tests your code on the 2 examples above. Submit runs all 6 tests, including hidden edge cases, and marks the challenge solved.

    solution.py
    Loading Python…

    Test results show up here

    Write count_baubles in the editor, then press Check. Use print() freely: its output is shown for each test.