File size: 323 Bytes
0981686
 
 
 
 
 
 
1
2
3
4
5
6
7
8
Done. Created `fib.py` and verified with `python3 fib.py`.

**Results:**
- `fib(10) == 55` ✓
- Negative `n` raises `ValueError` ✓ (tested with `-1` and `-5`)

The function uses iteration with a two-variable loop, so it runs in O(n) time and O(1) space, and handles the edge cases `fib(0)==0` and `fib(1)==1` correctly.