In this program, you will learn how to find factorial of a number using multilevel inheritance in Python.
3! = 1 * 2 * 3
4! = 1 * 2 * 3 * 4
5! = 1 * 2 * 3 * 4 * 5
class First:
def __init__(self):
self.num = int(input("Enter a number:"))
self.f = 1
class Second(First):
def fact(self):
for i in range(1, self.num + 1):
self.f = self.f * i
class Third(Second):
def result(self):
print("Factorial is:", self.f)
obj = Third()
obj.fact()
obj.result()
Enter a number:4
Factorial is: 24