def fib(n): if n < 0: raise ValueError("n must be non-negative") a, b = 0, 1 for _ in range(n): a, b = b, a + b return a