Python Program to find the largest of three numbers using multilevel inheritance


In this program, you will learn how to find the largest of three numbers using multilevel inheritance in Python.


10 20 10 => 20

20 12 10 => 20

Example: How to find the largest of three numbers using multilevel inheritance in Python

class First:
    def __init__(self):
        self.num1 = int(input("Enter first number:"))
        self.num2 = int(input("Enter second number:"))
        self.num3 = int(input("Enter third number:"))
        self.large = 0


class Second(First):
    def check(self):
        if self.num1 > self.num2 and self.num1 > self.num3:
            self.large = self.num1
        elif self.num2 > self.num3:
            self.large = self.num2
        else:
            self.large = self.num3


class Third(Second):
    def result(self):
        print("Largest number is:", self.large)


obj = Third()
obj.check()
obj.result()

Output:

Enter first number:10
Enter second number:30
Enter third number:20
Largest number is: 30