Simple Calculator || Hybrid Inheritance || Python
In this we are going to see a basic program on how to create a simple calculator using hybrid inheritance in Python Programming Language.


class Parent_class1:
    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


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

class Upper_child(Parent_class1,Parent_class2):
    def subraction(self):
        print("Subraction value1 : ", self.value1)
        print("Subraction value2 : ", self.value2)
        return self.value1 - self.value2

    def mod(self):
        print("Modulus value1 : ", self.value1)
        print("Modulus value2 : ", self.value2)
        return self.value1 % self.value2


class Child_class(Upper_child):
    def __init__(self, value1, value2):
        self.value1 = value1
        self.value2 = value2


Object1 = Child_class(10, 15)
print("Added value :", Object1.Addition())
print(" ")
Object2 = Child_class(20, 30)
print("Multiplied value :", Object2.multiplication())
print(" ")
Object3 = Child_class(50, 30)
print("Subracted value :", Object3.subraction())
print(" ")
Object4 = Child_class(70, 20)
print("Division value :", Object4.divison())
print(" ")
Object5 = Child_class(6, 2)
print("Power value :", Object5.power())
print(" ")
Object6 = Child_class(16, 7)
print("Modulus value :", Object6.mod())

# 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