Calculator using Multiple Inheritance || Multiple Inheritance || Python
In this we are going to see a basic example of how to build a calculator using multiple inheritance in Python Programming Language.



class Parent_class1:

    # To perform addition
    def Addition(self):
        print("Addition value1 : ", self.value1)
        print("Addition value2 : ", self.value2)
        return self.value1 + self.value2

    def multiplication(self):
        print("Multiplication value1 : ", self.value1)
        print("Multiplication value2 : ", self.value2)
        return self.value1 * self.value2

    def subraction(self):
        print("Subraction value1 : ", self.value1)
        print("Subraction value2 : ", self.value2)
        return self.value1 - self.value2

class Parent_class2:
    def divison(self):
        print("Division value1 : ", self.value1)
        print("Division value2 : ", self.value2)
        return self.value1/self.value2

    def power(self):
        print("Power value1 : ", self.value1)
        print("Power value2 : ", self.value2)
        return self.value1**self.value2

# derived class or the sub class
class Child_class(Parent_class1,Parent_class2):
    def __init__(self, value1, value2):
        self.value1 = value1
        self.value2 = value2


# Driver code
Object1 = Child_class(10, 15)  # parent class object
print(" Added value :", Object1.Addition())
print(" ")
Object2 = Child_class(20, 30)  # parent class object
print(" Multiplied value :", Object2.multiplication())
print(" ")
Object3 = Child_class(50, 30)  # parent class object
print(" Subracted value :", Object3.subraction())
print(" ")
Object4 = Child_class(70, 20)  # parent class object
print(" Division value :", Object4.divison())
print(" ")
Object5 = Child_class(6, 2)  # parent class object
print(" Power value :", Object5.power())

# Coded by SAAHIL


#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post