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


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

Solution

class Fact:
    def __init__(self):
        self.cache = {0:1, 1:1}
    def fact(self, n):
        if n not in self.cache:
            self.cache[n] = self.fact(n-1) * n
        return self.cache[n]



List all Python Programs