Write a Python Program to print a list of fibonacci series for a given no using class


Topic: Write a Python Program to print a list of fibonacci series for a given no using class

Solution

class Fib:
    def __init__(self):
        self.cache = {1:1, 2:1}
    def fib(self, n):
        if n not in self.cache:
            print(f'Calculating fib({n})')
            self.cache[n] = self.fib(n-1) + self.fib(n-2)
        return self.cache[n]



List all Python Programs