Programming With Python Practical 15
Question 1
Create a class Employee with data members: name, department and salary. Create suitable methods for reading and printing employee information
emp.py
class Person:
name=""
def getData(self,n):
self.name=n
def putData(self):
print("Name is: ",self.name)
class Employee(Person):
department=""
salary=None
def get(self,dep,sal):
self.department=dep
self.salary=sal
def put(self):
print("Department is: ",self.department)
print("Salary is: ", self.salary)
e=Employee()
nm=input("Enter name: ")
dp=input("Enter department: ")
sl=int(input("Enter salary: "))
e.getData(nm)
e.get(dp,sl)
e.putData()
e.put()
Output

Question 2
Python program to read and print students information using two classes using simple inheritance.
stud.py
class Person:
name=""
def getData(self,n):
self.name=n
def putData(self):
print("Name is: ",self.name)
class Student(Person):
branch=""
rollno=None
def get(self,dep,sal):
self.branch=dep
self.rollno=sal
def put(self):
print("branch is: ",self.branch)
print("rollno is: ", self.rollno)
e=Student()
nm=input("Enter name: ")
br=input("Enter branch: ")
rn=int(input("Enter rollno: "))
e.getData(nm)
e.get(br,rn)
e.putData()
e.put()
Output

Question 3
Write a Python program to implement multiple inheritance
multiple.py
class Mammal:
def mammal_info(self):
print("Mammals can give direct birth.")
class WingedAnimal:
def winged_animal_info(self):
print("Winged animals can fly.")
class Bat(Mammal, WingedAnimal):
def bat_info(self):
print("Bat is both mammal and winged animal")
# create an object of Bat class
b1 = Bat()
b1.mammal_info()
b1.winged_animal_info()
b1.bat_info()
Output
