def fib_range(x, y):
    """Return a function that returns the next number in a series of fibonacci
    numbers, starting from x and ending with y, excluding y. Raise a
    StopIteration exception if there are no more numbers in the sequence.

    >>> fib = fib_range(2, 20)
    >>> [fib() for _ in range(5)]
    [2, 3, 5, 8, 13]
    >>> fib()
    Traceback (most recent call last):
        ...
    StopIteration
    """
    prev, curr = 0, 1
    def fib():
        nonlocal prev, curr
        if curr > y:
            raise StopIteration()
        prev, curr = curr, curr + prev
        return fib() if prev < x else prev
    return fib