Hello! I'm your AI assistant powered by AnyGpu. You can select a model from the sidebar and start chatting. How can I help you today?
Write a Python function to calculate fibonacci numbers.
Here's a Python function to calculate Fibonacci numbers:
def fibonacci(n):
    """Return the nth Fibonacci number."""
    if n <= 1:
        return n
    a, b = 0, 1
    for _ in range(2, n + 1):
        a, b = b, a + b
    return b

# Example usage
for i in range(10):
    print(f"F({i}) = {fibonacci(i)}")
This uses an iterative approach with O(n) time complexity and O(1) space complexity.