Write a Python function to calculate factorial of a given no using closer


Topic: Write a Python function to calculate factorial of a given no using closer

Solution

def fact():
    cache = {0:1, 1:1}
    def calc_fib(n):
        if n not in cache:
            print(f'Calculating fact({n})')
            cache[n] = calc_fib(n - 1) * n
        return cache[n]
    return calc_fib



List all Python Programs