0% found this document useful (0 votes)
13 views2 pages

A06

The document describes a Python program that defines an Employee class to manage employee information such as ID, name, salary, and department. It includes methods to display details, update salary, give bonuses, and change departments. An example employee is created and manipulated to demonstrate the functionality of the class.

Uploaded by

asimgalande
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)
13 views2 pages

A06

The document describes a Python program that defines an Employee class to manage employee information such as ID, name, salary, and department. It includes methods to display details, update salary, give bonuses, and change departments. An example employee is created and manipulated to demonstrate the functionality of the class.

Uploaded by

asimgalande
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/ 2

"""Title: Write a python program to create employee class that

-Store Employee info(ID,name,salary,department)


-Update salary or give bonuses
-Change department
-Display Employee details

Name: Harshal Kiranrao Bhadane


Roll No:13
Batch :CA1
Date : 08/04/2025
"""

class Employee:
def __init__(self, emp_id, name ,salary,department):
self.emp_id=emp_id
self.name = name
self.__salary=salary
self.department = department

def display_details(self):
print(f"Employee ID :{self.emp_id}")
print(f"Name :{self.name}")
print(f"Salary :${self.__salary}")
print(f"Department :{self.department}")

def get_salary(self):
return self.__salary

def set_salary(self,new_salary):
if new_salary >=0:
self.__salary =new_salary
print(f"Salary updated to ${self.__salary}")
else:
print("Invalid Salary")

def give_bonus(self,amount):
if amount>0:
self.__salary += amount
print(f"Bonus of ${amount} added.New salary is ${self.__salary}")
else:
print("Bonus must be positive!")

def update_department(self,new_department):
self.department = new_department
print(f"Department changed to :{self.department}")

emp1 = Employee(101,"ABC",5000,"IT")

print("===Initial Employee Details===")


emp1.display_details()

print("\n-- Giving bonus of $3000---")


emp1.give_bonus(3000)

print("\n---Updating salary to $6000---")


emp1.set_salary(6000)

print("\n---Changibg Department to Finance---")


emp1.update_department("Finance")

print("\n---Updated Employee Details---")


emp1.display_details()

"""
Output:-
cc76@cc76:~$ python3 h00.py
===Initial Employee Details===
Employee ID :101
Name :ABC
Salary :$5000
Department :IT

-- Giving bonus of $3000---


Bonus of $3000 added.New salary is $8000

---Updating salary to $6000---


Salary updated to $6000

---Changibg Department to Finance---


Department changed to :Finance

---Updated Employee Details---


Employee ID :101
Name :ABC
Salary :$6000
Department :Finance

"""

You might also like