Q:

Python program to get employee details and search for record by ID, surName or Designation

belongs to collection: Python basic programs

0

We will take multiple inputs from the user on employee details like idnamelastNamesalary and designation and store it into a list.

Then, we will search for a specific record from the list using its IDsurName or Designation.

Algorithm:

  • Step 1: Get input from the user on IDnamelastName, salary and grade. And then store it in a list.
  • Step 2: Get user input for ID to be searched, if it matches the data in the list, print the data otherwise print "employee does not exist".
  • Step 3: Get user input for surName to be searched, if it matches the data in the list, print the data otherwise print "employee does not exist".
  • Step 4: Get user input for Designation to be searched, if it matches the data in the list, print the data otherwise print "employee does not exist".

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to get and search details

class Employee:
    def GetEmployee(self):
        print("Enter Employee Details : ")
        self.__id = input("Id : ")
        self.__name = input("Name : ")
        self.__lastname = input("Surname : ")
        self.__salary = int(input("Salary : "))
        self.__grade = input("Designation Level (I,II,III) : ")

    def PutEmployee(self):
        print(self.__id, self.__name, self.__salary)

    def Perks(self):
        self.PutEmployee()
        if (self.__grade == '1'):
            da = self.__salary * 40 / 100;
            hra = self.__salary * 16 / 100;
        elif (self.__grade == '2'):
            da = self.__salary * 50 / 100;
            hra = self.__salary * 18 / 100;
        elif (self.__grade == '3'):
            da = self.__salary * 60 / 100;
            hra = self.__salary * 20 / 100;

        ns = self.__salary + da + hra
        print(da, hra, ns)

    def Search(self, id):
        if id == self.__id:
            return True
        else:
            return False

    def search(self, grade):
        if grade == self.__grade:
            return True
        else:
            return False

    def tsearch(self, lastname):
        if lastname == self.__lastname:
            return True
        else:
            return False

n = int(input("Enter Total No. of Employees?"))
L = list()
for i in range(n):
    E = Employee()
    E.GetEmployee()
    L.append(E)
id = input("Enter Id U Want to Search?")

found = False
for e in L:
    found = e.Search(id)

    if (found):
        e.Perks()
        break
if (not found):
    print("Employee Not Exist")

lastname = input("Employee does not exist")
found = False
for e in L:
    found = e.tsearch(lastname)

    if (found):
        e.Perks()
        break
if (not found):
    print("Employee does not exist")

grade =input ("enter designation")

found = False
for e in L:
    found = e.search(grade)

    if (found):
        e.Perks()
        break
if (not found):
    print("Employee does not exist")

Output:

Enter Total No. of Employees?4
Enter Employee Details : 
Id : 01
Name : JOhn    John
Surname : 34  Doe 
Salary : 45000
Designation Level (I,II,III) : 2
Enter Employee Details : 
Id : 4
Name : Ram 
Surname : Singh
Salary : 25000
Designation Level (I,II,III) : 1
Enter Employee Details : 
Id : 56
Name : Nupur 
Surname : Dubey
Salary : 65000
Designation Level (I,II,III) : 3
Enter Employee Details : 
Id : 43
Name : Jane
Surname : Doe
Salary : 34123
Designation Level (I,II,III) : 2
Enter Id U Want to Search?43
43 Jane 34123
17061.5 6142.14 57326.64
enter surname Dubey
56 Nupur  65000
39000.0 13000.0 117000.0
enter designation1
4 Ram  25000
10000.0 4000.0 39000.0

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python basic programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python program for Basic Shop Management System... >>
<< Python program to calculate gross pay (Hourly paid...