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


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

Solution

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



List all Python Programs