In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how Python can add, delete and change the staff management system, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
1. Analysis (1) outline
1. First create an empty list to store employee information, that is, employee = []. 2. The management system mainly carries out infinite loops through while True statements. If the while conditional judgment statement is always True, the loop will execute infinitely. In the loop, you can use the continue statement and the break statement to jump out of this loop and the whole loop, respectively. 3. Set six numbers 1-6 in turn to correspond to different operations on the system. Here, an if-else statement is used. If the input number is not in 1-6, the loop will end break, otherwise the corresponding operation will be carried out.
(2) add employees
In the function of adding employees, it is easier to add a batch of employees by entering the number of employees to be added, mainly through the for loop and the range () function, according to the number of employees entered to determine the number of code blocks executed in the for loop, namely for p in range (e_number). The newly added employee is assigned a new_employee variable, through the append () method, that is, employee.append (new_employee), to add new elements to the empty list employee (note that the append () method is used here, so the newly added elements are added from the end).
(3) deletion of employees
In the delete employee function, the employee to be deleted is assigned a del_employee variable, and the employee is deleted from the list through the remove () method, that is, employee.remove (del_employee). (note that the remove () method is used here, and if there are multiple matching elements to be deleted in the list, only the first matching element will be deleted.)
(4) find employees
In the function of finding employees, the employee to be found is assigned a search_employee variable, an if-else statement is set, and if the employee does not exist in the list, an if-else statement is made to confirm whether to add the unfound employee through the user's input of YUnip N. if it is not needed, the employee can jump out of this cycle through continue. Instead of adding employees as before, you just need to use the append () method with the variable search_employee of the employee to be queried.
(5) revision of staff
First of all, through the definition of pre-modified and modified employees, through input () input. This is equivalent to modifying the list employee by re-assigning values to the list elements.
2. Implement code print ("- employee management system -") print ("1, add employee information") print ("2, delete employee information") print ("3, find employee information") print ("4, modify employee information") print ("5, output employee information table") print ("6. Exit the system ") print ("-employee management system-") employee = [] while True: number = int (input (" Please enter the appropriate number for appropriate operation: ") if number 6: print (" input error! ") Break else: if number = = 1: e_number = int (input ("Please add the number of employees:") for p in range (e_number): new_employee = input ("Please enter employees to add:") employee.append (new_employee) print (f "added successfully! {e_number} employees have been added!") Elif number = = 2: del_employee = input ("Please enter the employee to delete:") employee.remove (del_employee) print (f "employee {del_employee} deleted successfully!") Elif number = = 3: search_employee = input ("Please enter the employee you want to find:") if search_employee in employee: print ("the employee has been found!") Else: print ("this employee does not exist! do you want to add this new employee?") Affirm = input ("Please enter Y search_employee N to confirm:") if affirm = = "Y": employee.append (search_employee) print (f "added successfully! {search_employee} employees!") Else: continue elif number = = 4: mod_employee = input ("Please enter the employee to be modified:") index = employee.index (mod_employee) moded_employee = input ("Please enter the modified employee:") employee [index] = moded_employee print (f "the original employee has been modified The modified employee is {moded_employee} ") elif number = = 5: for i in employee: print (I) elif number = = 6: break III.
Run the program:
If you enter a number other than 1-6, you will exit the program:
Test the add function, enter 5 employee information, and because the defined while statement is an endless loop, the program runs until the breakstatement exits:
Test the delete function to delete the specified employee information:
Test the search function to find the specified employee information: if the employee you are looking for is not available, you can add it to the system, or you can choose not to add it, it will jump out of this cycle.
Test the modification function to modify the specified employee information:
Test output information, output information for all employees:
Exit the program:
The above is all the contents of this article "how to add, delete, change and query the employee management system in Python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 215
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.