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

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.