Ad Code

Responsive Advertisement

Basic Python Program - 55

Question 55: Write a Python program to implement multiple inheritance. (Addition, Multiplication, Division)
Download hole Program / Project code, by clicking following link:
Program Explanation:
The Python program demonstrates multiple inheritance. In this example, you have three classes: Add, Mul, and Div, where Div inherits from both Add and Mul.

Output:
Addition is: 30
Multiplication is: 200
Division is: 0.5


Here's a breakdown of what the program does:
  1. The Add class defines a method called addition that returns the sum of two numbers.
  2. The Mul class defines a method called multiplication that returns the product of two numbers.
  3. The Div class inherits from both Add and Mul, which means it has access to the methods defined in both parent classes.
  4. An object obj of the Div class is created.
  5. The program calls the methods on obj to perform addition, multiplication, and division operations.
  6. The Mul class defines a method called multiplication that returns the product of two numbers.
This example demonstrates the concept of multiple inheritance, where a class inherits from multiple parent classes, enabling it to access and use methods and attributes from all parent classes.
Programming Code:
Following code write in: BP_P55.py
# Python Program

# Multiple Inheritance

class Add:

    # Method 
    def addition(self, num1, num2):
        return (num1 + num2)

class Mul:
    # Method
    def multiplication(self, num1, num2):
        return (num1 * num2)

# Multiple Inheritance
class Div(Add, Mul):

    # Method
    def divide(self, num1, num2):
        return (num1 / num2)

# Create object
obj = Div()

# Call Method

print("Addition is: ", obj.addition(10, 20))
print("Multiplication is: ", obj.multiplication(10, 20))
print("Division is: ", obj.divide(10, 20))

# Thanks for Reading.
Output:

Post a Comment

0 Comments

Ad Code

Responsive Advertisement