Skip to content

Added fibonacci.py with fib(n) and main#691

Open
opencode-agent[bot] wants to merge 1 commit intomainfrom
opencode/issue690-20260330052146
Open

Added fibonacci.py with fib(n) and main#691
opencode-agent[bot] wants to merge 1 commit intomainfrom
opencode/issue690-20260330052146

Conversation

@opencode-agent
Copy link
Copy Markdown

Implemented the fibonacci.py script at the repo root.

What I added

  • fibonacci.py
    • Function fibonacci(n)
      • Docstring explaining the definition: F(0)=0, F(1)=1, F(n)=F(n-1)+F(n-2)
      • Iterative implementation with O(n) time and O(1) space
      • Raises ValueError for negative n
    • main block
      • Prints the first 10 Fibonacci numbers: F(0) through F(9)
      • Output format: a single line with numbers separated by spaces
        • Example output: 0 1 1 2 3 5 8 13 21 34

Code (for quick reference)

  • fibonacci.py
    • Function:
      • def fibonacci(n):
        • """Return the nth Fibonacci number..."""
        • if n < 0: raise ValueError(...)
        • a, b = 0, 1
        • for _ in range(n): a, b = b, a + b
        • return a
    • Main:
      • if name == "main":
        • line = " ".join(str(fibonacci(i)) for i in range(10))
        • print(line)

This should satisfy Issue #690 requirements:

  • Defines fibonacci(n) returning the nth Fibonacci number
  • Includes a docstring for the function
  • main prints the first 10 Fibonacci numbers

If you’d like a different output format (e.g., one per line) or a different starting index, I can adjust quickly.

Closes #690

New%20session%20-%202026-03-30T05%3A21%3A44.861Z
opencode session  |  github run

Co-authored-by: dzianisv <dzianisv@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a fibonacci.py script

0 participants