|Artificial Intelligence Tutorial|
|Machine Learning Projects Tutorial||Python Video tutorial|
|Computer Graphics Video Tutorial||C++ Video Tutorial|
|Big Data Analytics Video Tutorial||Soft Computing Video Tutorial|
|Placement Video Tutorial||Java Video Tutorial|
Python program to keep track of the number of employees in an organization
Write a python program to keep track of the number of employees in an organization and also store and display their name, designation, and salary details.
As said in the problem definition, first create a class named Employee. The class Students have three methods, the init() method also known as a constructor, displayCount(), and displayEmp() method.
The Employee class has a class variable named count, which is used to track the number of employees in the organization. As count is a class variable we cannot access this variable directly. We need to use the class name to access the class variable.
init() method is called whenever an object of a class is created and used to initialize the attributes of the object. The class variable count is incremented as and when a new employee object is created.
DisplayCount() method is used to print the number of employees in the organization.
DisplayEmp() method is used to display the employee information such as employee name, employee designation, and employee salary.
Finally, in the main part of the program, two employee objects are created. Then the number of employees working in the organization is displayed by calling the displayCount() method and employee information is displayed by calling displayEmp() method.
Source code for Python program to keep track of the number of employees in an organization
class Employee: count = 0 def __init__(self, name, des, salary): self.name = name self.des = des self.salary = salary Employee.count = Employee.count + 1 def displayCount(self): print("The number of employees in the organization are: ", self.count) def displayEmp(self): print ("Name of Employee is: ", self.name) print ("Designation of Employee: ", self.des) print ("Salary of Employee: ", self.salary) e1 = Employee ("Mahesh", "Manager", 20000) e2 = Employee ("Rahul", "Team Leader", 30000) e1.displayCount() print("Employee Details is:") e1.displayEmp() e2.displayEmp()
The number of employees in the organization are: 2
Employee Details is:
Name of Employee is: Mahesh
Designation of Employee: Manager
Salary of Employee: 20000
Name of Employee is: Rahul
Designation of Employee: Team Leader
Salary of Employee: 30000
This article discusses, how to write a Python program to keep track of the number of employees in a company. Subscribe to our YouTube channel for more videos and like the Facebook page for regular updates.