Pract15
Pract15
Multiuple Inheritance:
class Add:
def Addition(self,a,b):
return a+b;
class Mul:
def Multiplication(self,a,b):
return a*b;
class Derived(Add,Mul):
def Divide(self,a,b):
return a/b;
d = Derived()
print(d.Addition(10,20))
print(d.Multiplication(10,20))
print(d.Divide(10,20))
Output:
1|Page
Subject: PWP[22616]
Practical No.15: demonstrate following operations: Simple inheritance, Multiple inheritance
Name: Ritesh Doibale Roll no:41
X.Exercise.
Q1. Create a class Employee with data members: name, department and salary. Create suitable
methods for reading and printing employee information
class Employee:
name = ""
department = ""
salary = 0
def read_employee_info(self):
self.name = input("Enter the employee name: ")
self.department = input("Enter the employee department: ")
self.salary = float(input("Enter the employee salary: "))
def print_employee_info(self):
print(f"Name: {self.name}")
print(f"Department: {self.department}")
print(f"Salary: {self.salary}")
emp=Employee()
emp.read_employee_info()
emp.print_employee_info()
Output:
Q2. Python program to read and print students information using two classes using simple inheritance
class Student_Details:
def __init__(self):
self.name = input("Enter Your Name: ")
self.cname=input("Enter Your College Name: ")
self.roll = int(input("Enter Your Roll Number: "))
class Temp(Student_Details):
def display(self):
print("============ Student Details are ==========")
print("Name: ", self.name)
print("College Name:", self.cname)
print("Roll number:", self.roll)
2|Page
Subject: PWP[22616]
Practical No.15: demonstrate following operations: Simple inheritance, Multiple inheritance
Name: Ritesh Doibale Roll no:41
obj1 = Temp()
obj1.display()
Output:
class A:
def __init__(self):
self.var_a = "I am from class A"
def display_a(self):
print(self.var_a)
class B:
def __init__(self):
self.var_b = "I am from class B"
def display_b(self):
print(self.var_b)
obj = C()
obj.display_a()
obj.display_b()
Output:
3|Page