0% found this document useful (0 votes)
19 views5 pages

Python Pra 15

The document contains Python code examples demonstrating class creation and inheritance. It includes an Employee class for managing employee information, a Person and Student class for handling student data through inheritance, and a Manager class that showcases multiple inheritance from both Person and Employee classes. Each section provides code for reading and printing relevant information for each class type.

Uploaded by

birhadepranusha
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)
19 views5 pages

Python Pra 15

The document contains Python code examples demonstrating class creation and inheritance. It includes an Employee class for managing employee information, a Person and Student class for handling student data through inheritance, and a Manager class that showcases multiple inheritance from both Person and Employee classes. Each section provides code for reading and printing relevant information for each class type.

Uploaded by

birhadepranusha
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/ 5

Gramin Technical and Management Campus

Department of computer engineering


Subject/code: -Python/22616

Name:-Pranusha Shiddhodhan Birhade

DOP: DOS:-

Practical No 15
1) Create a class Employee with data members: name, department and
salary. Create suitable methods for reading and printing employee
information

Code:-
class Employee:

def __init__(self, name="", department="", salary=0.0):

self.name = name

self.department = department

self.salary = salary

def read_employee_info(self):

self.name = input("Enter employee name: ")

self.department = input("Enter employee department: ")

self.salary = float(input("Enter employee salary: "))

def print_employee_info(self):

print("\nEmployee Information:")

print(f"Name: {self.name}")

print(f"Department: {self.department}")

print(f"Salary: ${self.salary:.2f}")

if __name__ == "__main__":
employee = Employee()

employee.read_employee_info()

employee.print_employee_info()

Output:-

2) Python program to read and print students information using two


classes using simple inheritance.

Code:-
class Person:

def __init__(self, name="", age=0):

self.name = name

self.age = age

def read_person_info(self):

self.name = input("Enter name: ")

self.age = int(input("Enter age: "))

def print_person_info(self):

print(f"Name: {self.name}")

print(f"Age: {self.age}")

class Student(Person):

def __init__(self, name="", age=0, student_id="", major=""):


super().__init__(name, age)

self.student_id = student_id

self.major = major

def read_student_info(self):

self.read_person_info()

self.student_id = input("Enter student ID: ")

self.major = input("Enter major: ")

def print_student_info(self):

self.print_person_info()

print(f"Student ID: {self.student_id}")

print(f"Major: {self.major}")

if __name__ == "__main__":

student = Student()

student.read_student_info()

print("\nStudent Information:")

student.print_student_info()

Output:-
3) Write a Python program to implement multiple inheritance

Code:-
class Person:

def __init__(self, name, age):

self.name = name

self.age = age

def display_person_info(self):

print(f"Name: {self.name}")

print(f"Age: {self.age}")

class Employee:

def __init__(self, employee_id, department):

self.employee_id = employee_id

self.department = department

def display_employee_info(self):

print(f"Employee ID: {self.employee_id}")

print(f"Department: {self.department}")

class Manager(Person, Employee):

def __init__(self, name, age, employee_id, department, team_size):

Person.__init__(self, name, age)

Employee.__init__(self, employee_id, department)

self.team_size = team_size

def display_manager_info(self):

self.display_person_info()

self.display_employee_info()

print(f"Team Size: {self.team_size}")

if __name__ == "__main__":

manager = Manager("pranusha", 17, "101", "IT", 20)


print("Manager Information:")

manager.display_manager_info()

Output:-

You might also like