Python program to keep track of the number of employees in an organization

Python program to keep track of the number of employees in an organization

Problem Description:

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.

Program Description:

As said in the problem definition, first create a class named Employee. The class Students has 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 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.

READ  Solution to Python Application Programming Question Paper Jan 2019 15CS664

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 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 Employess 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()

Output:

The number of Employess 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

Video Tutorial

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.

Leave a Comment

Your email address will not be published. Required fields are marked *