0% found this document useful (0 votes)
15 views3 pages

PWP Prac 15

The document provides Python programming exercises focused on creating classes and implementing inheritance. It includes examples for creating an Employee class, a Person class with a Student subclass, and a Child class that inherits from two parent classes. Each example demonstrates how to read and display information using methods within the classes.

Uploaded by

saeedarwatkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

PWP Prac 15

The document provides Python programming exercises focused on creating classes and implementing inheritance. It includes examples for creating an Employee class, a Person class with a Student subclass, and a Child class that inherits from two parent classes. Each example demonstrates how to read and display information using methods within the classes.

Uploaded by

saeedarwatkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical

ractical No. 15

1) Create a class Employee with data members name, department and salary. Create
suitable methods for reading and printing employee information.
class Employee:
def __init__(self, name, department, salary):
self.name = name
self.department
.department = department
self.salary = salary

def display_info(self):
print("Employee Name:", self
self.name)
print("Department:", self
self.department)
print("Salary:", self.salary)
.salary)

name = input("Enter
"Enter Employee Name: "")
department = input("Enter
"Enter Department: "
")
salary = float(input("Enter
"Enter Salary: "
"))

emp = Employee(name, department, salary)


emp.display_info()

Output:
2) write a python program to rread
ead and print student information using two classes using
simple inheritance
class Person:
def __init__(self,
, name, age):
self.name = name
self.age = age

def display_info(self):
print("Name:", self.name)
.name)
print("Age:", self.age)

class Student(Person):
def __init__(self,
, name, age, grade):
super().__init__(name,
(name, age)
self.grade = grade

def display_info(self):
super().display_info()
print("Grade:", self.grade)
.grade)

name = input("Enter
"Enter Student Name: "
")
age = int(input("Enter Age: "))
grade = input("Enter Grade: ")

student = Student(name, age, grade)


student.display_info()

Output:
3) Write a python program to implement multiple inheritance.
class Parent1:
def display1(self):
print("This is Parent 1")
)

class Parent2:
def display2(self):
print("This is Parent 2")
)

class Child(Parent1, Parent2):


def display_child(self):
print("This
"This is Child class"
class")

obj = Child()
obj.display1()
obj.display2()
obj.display_child()

Output:

You might also like