Programmin-in-Python

Adding an Employee's Details using Employee Class

Jan 15th, 2021
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. class Employee:
  2.     """Creates a Employee Class"""
  3.     def __init__(self):
  4.         self.Details = dict()
  5.  
  6.     def add_details(self, empid, empname, empsal):
  7.         self.Details[empid] = (empname, empsal)
  8.  
  9.     def show_details(self, empid):
  10.         return self.Details.get(empid, "")
  11.  
  12.     def count(self):
  13.         return len(self.Details)
  14.  
  15. employee = Employee()
  16. print("There are No Details of any Employee!!!\nPlease Enter the Details of Employees First...")
  17. choice_get, choice_put = "y", "y"
  18.  
  19. while choice_put.lower() == "y":
  20.     empid = int(input("Enter the Employee ID : "))
  21.     empname = input("Enter the Name of Employee : ")
  22.     empsal = int(input("Enter the Salary of the Employee : "))
  23.  
  24.     employee.add_details(empid, empname, empsal)
  25.     print("\nThe Record has been Added Successfully!!!")
  26.  
  27.     choice_put = input("\nDo You Want to Add More Details of Employees(Y/[N]) : ")
  28.  
  29. print(f"\nYou've Added {employee.count()} Records Successfully!!!\nNow You may Retrieve any Record...")
  30. while choice_get.lower() == "y":
  31.     empid = int(input("Enter the ID of the Employee's Record to be Retrieved : "))
  32.     details = employee.show_details(empid)
  33.  
  34.     if any(details):
  35.         print("\nThe Name of the Employee : ", details[0])
  36.         print("The Salary of the Employee : ", details[1])
  37.     else:
  38.         raise KeyError(f"Oops!!! There is no Such Employee with ID as {empid}")
  39.  
  40.     choice_get = input("\nDo You Want to Retrieve More Details of Employees(Y/[N]) : ")
  41. else:
  42.     print("Thank You!!!")
Advertisement
Add Comment
Please, Sign In to add comment