this is a pure python implementation of dynamic programming solution to the fibonacci sequence problem get the fibonacci number of index if the number does not exist calculate all missing numbers leading up to the number of index fibonacci get10 0 1 1 2 3 5 8 13 21 34 fibonacci get5 0 1 1 2 3 get the fibonacci number of index if the number does not exist calculate all missing numbers leading up to the number of index fibonacci get 10 0 1 1 2 3 5 8 13 21 34 fibonacci get 5 0 1 1 2 3
class Fibonacci:
    def __init__(self) -> None:
        self.sequence = [0, 1]

    def get(self, index: int) -> list:
        
        if (difference := index - (len(self.sequence) - 2)) >= 1:
            for _ in range(difference):
                self.sequence.append(self.sequence[-1] + self.sequence[-2])
        return self.sequence[:index]


def main() -> None:
    print(
        "Fibonacci Series Using Dynamic Programming\n",
        "Enter the index of the Fibonacci number you want to calculate ",
        "in the prompt below. (To exit enter exit or Ctrl-C)\n",
        sep="",
    )
    fibonacci = Fibonacci()

    while True:
        prompt: str = input(">> ")
        if prompt in {"exit", "quit"}:
            break

        try:
            index: int = int(prompt)
        except ValueError:
            print("Enter a number or 'exit'")
            continue

        print(fibonacci.get(index))


if __name__ == "__main__":
    main()