Skip to main content

Python Programming: An Employee Management System

For the final project I had taken all my previously built scripts and refined them into one solid script. I added a menu option to allow the user to choose between all the listed options. Adding in the ability to add an employee was the first option I wanted to write in the script as it laid the groundwork for the rest of the functions to work properly. I then went on to write in the global count. I chose this option next because that would tell me if my “add an employee” part of the script was working properly. Lastly, I added in the ability to show all the employees that have been entered into the system. Throughout the entire script I made sure to utilize the “import os” function so that all the data that was output was not cluttered and it was easy to View. 

The purpose of the “add an employee” function is to allow the user to add multiple users to the employee management system. The purpose of the “show all employees” function is to allow the user to see which employees have been entered into the system already. Also, the added ability to see how many employees are entered into the system can tell the user whether they have added the right number of employees they were looking for. Adding in the search and edit employee menu option is a fantastic addition to the employee management system. The search function makes it much easier for the user to find an employee quicker rather than looking through the full list of employees. The edit employee option allows the user to edit a specific employee that has already been entered into the system. 

For the import and export function to the employee management system. To import the .txt file into the program I had to create an open list under the “def import_emp(fname):” so that the imported file will have a place to store the information. Next, was the command to have the program open the file and then follow up with modifying the imported file so the program can read the data correctly. For the export command, I started by having the program open a specifically named .txt file so the user would know where the information was being written to. I then went on to add in the lines of code that covered how the program was going to write the information to the saved file and concluded with it closing the saved file. The purpose of the import function is to allow the user to upload a .txt file containing employee information. This can be useful because it saves time by importing multiple employees at one time rather than entering each person individually. The purpose of the export function is to take all the employee information that has been entered into the system and export it to a .txt file. Doing so will allow the user to manipulate the exported data however they may need. 

Overall, the employee management system is a great way for a user to keep track of data while being able to manipulate it at the same time. The script can also be modified to import a file at the beginning of the program running to serve as a “save” point one the database has been started. I feel that this project was a great start into getting to understand the way python works. 



Script 

employees = [] 
count = 0 
  
import time 
 
def export_emp(employees): 
  fopen = open("EmployeeDatabase.txt", "a") 
  for employee in employees: 
    for i in employee: 
      fopen.write(i+" ") 
    fopen.write("\n") 
  fopen.close() 
  
def import_emp(fname): 
  temp = [] 
  fopen = open(fname,"r") 
  for line in fopen: 
    line = line.strip() 
    if len(line) != 0: 
      line = line.split() 
      temp.append(line) 
  fopen.close() 
  return temp 
  
def Add_Employee(): 
  global count 
  Employee = [] 
  count += 1 
  print('Enter name of employee: ',end='') 
  Employee.append(input()) 
  print('Enter employee SSN: ',end='') 
  Employee.append(input()) 
  print('Enter employee phone number: ',end='') 
  Employee.append(input()) 
  print('Enter employee email: ',end='') 
  Employee.append(input()) 
  print('Enter employee salary: $',end='') 
  Employee.append(input()) 
  employees.append(Employee) 
  import os 
  os.system('cls' if os.name == 'nt' else "printf '\033c'") 
  
def view_all_Employees(employees): 
  for i in employees: 
    print('---------------------------- '+i[0]+' ---------------------------------------') 
    print('SSN: ', i[1]) 
    print('Phone: ', i[2]) 
    print('Email: ', i[3]) 
    print('Salary: ', i[4]) 
    print('------------------------------------------------------------------------') 
  
def search_Employee(ssn): 
  findIdex = 0 
  for i in employees: 
    if(i[1]==ssn): 
      return findIdex 
    findIdex+=1 
  return-1 
  
def main(): 
  global count 
  global employees 
while(True): 
  print("------------------------ Employee Management System ----------------------------\n") 
  print('Enter -1 to exit') 
  print('\nThere are (',count,') employees in the database.') 
  print('--------------------------------------------------------------------------------') 
  print('1. Add new employee.\n') 
  print('2. View all employees.\n') 
  print('3. Search employee by SSN.\n') 
  print('4. Edit employee information.\n') 
  print('5. Export employees information into a text file.\n') 
  print('6. Import employees information from a text file.') 
  print('---------------------------------------------------------------------------------\n') 
  print('Please enter your option number: ', end="") 
  a=float(input()) 
  import os 
  os.system('cls' if os.name == 'nt' else "printf '\033c'") 
  if(a==-1): 
    import os 
    os.system('cls' if os.name == 'nt' else "printf '\033c'") 
    quit() 
  elif (a==1): 
    Add_Employee() 
    print() 
  elif(a==2): 
    view_all_Employees(employees) 
    print() 
    input("Press ENTER to return to the main menu.") 
    import os 
    os.system('cls' if os.name == 'nt' else "printf '\033c'") 
  elif(a==3): 
    ssn=input("Enter Employee SSN: ") 
    import os 
    os.system('cls' if os.name == 'nt' else "printf '\033c'") 
    empIndex=search_Employee(ssn) 
    if(empIndex>=0): 
      print("---------------------------- "+employees[empIndex][0]+" ---------------------------------------") 
      print('SSN:',employees[empIndex][1]) 
      print('Phone:',employees[empIndex][2]) 
      print('Email:',employees[empIndex][3]) 
      print('Salary:',employees[empIndex][4]) 
      print("------------------------------------------------------------------------\n") 
      input("Press ENTER to return to the main menu.") 
      import os 
      os.system('cls' if os.name == 'nt' else "printf '\033c'") 
    else: 
      import os 
      os.system('cls' if os.name == 'nt' else "printf '\033c'") 
      print("Employee "+ssn+" not found.\n") 
      input("Press ENTER to return to the main menu.") 
      import os 
      os.system('cls' if os.name == 'nt' else "printf '\033c'") 
  elif(a==3.5): 
    print("Congrats on finding the Easter Egg!\n") 
    time.sleep(1) 
    print("5\n") 
    time.sleep(1) 
    print("4\n") 
    time.sleep(1) 
    print("3\n") 
    time.sleep(1) 
    print("2\n") 
    time.sleep(1) 
    print("1") 
    import antigravity 
    input("\nPress ENTER to return to the main menu.") 
    import os 
    os.system('cls' if os.name == 'nt' else "printf '\033c'") 
  elif(a==4): 
    ssn=input("Enter the SSN of the employee you would like to update: ") 
    empIndex=search_Employee(ssn) 
    if(empIndex>=0): 
      employees[empIndex][0]=input("Ente updated name: ") 
      employees[empIndex][2]=input("Enter updated phone number: ") 
      employees[empIndex][3]=input("Enter updated email address: ") 
      employees[empIndex][4]=input("Enter updated salary: $") 
      print("\nEmployee information has been updated successfully.\n") 
      input("Press ENTER to return to the main menu.") 
      import os 
      os.system('cls' if os.name == 'nt' else "printf '\033c'") 
    else: 
      import os 
      os.system('cls' if os.name == 'nt' else "printf '\033c'") 
      print("Employee with "+ssn+" is not found.\n") 
      input("Press ENTER to return to the main menu.") 
      import os 
      os.system('cls' if os.name == 'nt' else "printf '\033c'") 
  elif(a==5): 
    export_emp(employees) 
    import os 
    os.system('cls' if os.name == 'nt' else "printf '\033c'") 
    print("Data Successfully Exported\n") 
    input("Press ENTER to return to the main menu.") 
    import os 
    os.system('cls' if os.name == 'nt' else "printf '\033c'") 
  elif(a==6): 
    employees = import_emp("EmployeeDatabase.txt") 
    count = count + len(employees) 
    print("Data Successfully Loaded\n") 
    input("Press ENTER to return to the main menu.") 
  else: 
    import os 
    os.system('cls' if os.name == 'nt' else "printf '\033c'") 
    print('Invalid option.\n') 
    input("Press ENTER to return to the main menu.") 
    import os 
    os.system('cls' if os.name == 'nt' else "printf '\033c'") 
  
main () 

Comments

Popular posts from this blog

Peering Points and the Network Application Interface

According to Gibb (2019), “Peering is a method that allows two networks to connect and exchange traffic directly without having to pay a third party to carry traffic across the Internet.” Utilizing a peering point allows users to send a receive data directly to one another without the need to route through other computer networks. Doing so allows for a quicker, more efficient, and safer form of communication.  Researching the total number of active Internet Exchange Points (IXP) proved difficult as it was hard to pinpoint an accurate number. However, according to Rosas (2021), “as of January 2021, of the 630 registered IXPs, 229 are in Europe, 126 in North America, 140 in Asia-Pacific, 96 in Latin America and the Caribbean (LAC), and 39 in Africa.” These numbers are constantly changing as new IXPs are added, and some are removed.  Finding a definitive number of Internet Service Providers (ISP) globally was also difficult to accomplish. Most sources seem to point to the Nations Encyclop

VLAN Aggregation for Efficient IP Address Allocation

The project I chose to summarize on the Internet Engineering Task Force (IETF) website was RFC: 3069, VLAN Aggregation for Efficient IP Address Allocation. Within this project, the authors point out how inefficiently a Virtual Local Area Network (VLAN) allocates IP addresses along with their proposed solutions. I have also attached a diagram showing how the network would look pertaining to this project. Currently, an IP subnet would be made for each existing customer by understanding how many hosts they currently need and may need in the future. Based on that total number, the IP subnet and gateway address would change according to how many hosts the customer requested. For example, if a customer has indicated that they need ten hosts, and they only use five, the additional five that are not in use cannot be used by another customer. An illustration of this is shown below. The proposed solution to this problem is to allocate IP addresses under the same IP subnet and gateway address uti

Access Lists and Capabilities

To implement an access matrix, we must first understand what it is. An access matrix is a protection model within an operating system consisting of objects and domains. The access matrix determines which processes interact with objects within the domain. Objects within the domain can consist of both hardware and software. The lists below show the advantages and disadvantages of access lists associated with objects, and capabilities with domains.  Access lists associated with objects Advantages  Corresponds directly to the user’s needs.  Easy revocation and review of access.  Disadvantages  Difficult to determine access rights for a domain.  Takes time to search the domain for access rights.  Capabilities with domains Advantages  Useful for localizing information for a process.  Secured against unauthorized access.  Disadvantages  Inefficient at the revocation of capabilities.  Does not correspond directly to the user’s needs.  Even though each implementation has its own strengths and w