In this article, we share the example of Python to achieve the specific code of the employee information management system for your reference, the specific content is as follows
1. Staff Information Management System
Request:
1、Enter each employee's information from the keyboard in turn, including name, employee id, ID number;
2. The eighteen digits of the ID number require that all but the 18th digit can be x, and the rest can only be numbers;
3. id shall consist of 5 digits;
4. Otherwise, the user is prompted to re-enter those items that do not conform to the rules;
5, can always view the entered employees and their information;
Tip:
1, string.isdigit () can determine whether the string is all numbers;
2、if String[-1] in "xX" Judge whether the last one is x or X;
3, each staff information can be saved in a dictionary, and then added to a staff list for management, if you want to view, traverse the staff list can be;
Reference Interface:
2. Reference code
info_list = [] admin_id = "python" password = "123456" while True: print("*********************** Staff Information Management System ***********************") print("-------------------------- 1. Add information --------------------------") print("-------------------------- 2. Query information --------------------------") print("-------------------------- 3. Delete information --------------------------") print("-------------------------- 4. Modify information --------------------------") print("-------------------------- 5. Query all --------------------------") print("-------------------------- 6. Exit the system --------------------------") print("*********************** Staff Information Management System ***********************") command = int(input("Please enter the corresponding number to proceed:")) print("-" * 30) # Separation line def add_info(a): # Add a function with parameters to be called on subsequent operations name = str(input("Please enter the employee's name:")) while True: # Consider, as a follow-up refinement, defining such loops as separate functions id_staff = str(input("Please enter employee ID:")) if id_staff.isdigit() is True and len(id_staff) == 5: # Determine if the employee ID is a 5-digit plain number break # End loop when input is correct else: print("-" * 50) # Separation line print("[ERROR_1]: Employee ID must be 5 plain digits, please re-enter!") print("-" * 50) # Separation line while True: # Consider, as a follow-up refinement, defining such loops as separate functions id_card = str(input("Please enter ID number:")) # Determine whether the ID number is eighteen digits, requiring that all but the 18th digit can be x if len(id_card) == 18 and id_card[-1] in "0123456789xX": num1 = id_card[0:17] if () is True: # Determine if the first 17 digits are numeric break else: print("-" * 35) # Separation line print("[ERROR_2]: The first 17 digits of the ID number must be numbers, please re-enter!") print("-" * 50) # Separation line else: print("-" * 60) # Separation line print("[ERROR_3]: ID number entered incorrectly, please re-enter!") print("The ID number must be 18 digits, with the first 17 digits being numbers and the last digit being a number or X!") print("-" * 60) # Separation line print("-" * 30) # Separation line info_dic = {} info_dic["Name"] = name info_dic["Employee ID"] = id_staff info_dic["ID number."] = id_card info_list.append(info_dic) if a == 1: print("[INFO_1]:Employee information added successfully!") else: print("[INFO_2]:Modification successful!") # Options called when modifying employee information print("-" * 30) # Separation line def find_info(b): # Followed by Search by Employee Name, Search by ID Number """Lookup function, called when the argument is a subsequent operation""" if verify(): # equivalent to if verify() is True: while True: # Consider defining such loops as separate functions in subsequent refinements. id_staff = str(input("Please enter employee ID:")) if id_staff.isdigit() is True and len(id_staff) == 5: # Determine if the employee ID is a 5-digit plain number break else: print("[ERROR_4]: Employee ID must be 5 plain digits, please re-enter!") print("-" * 30) # Separation line if len(info_list) == 0: print("[ERROR_5]: no such person found, please re-enter!") else: i = 0 while i < len(info_list): info_dic = info_list[i] if id_staff == info_dic.get('Employee ID'): if b == 2: # Called when searching print(info_dic) # Check to see if it's found else: return info_dic # Called on deletion and modification break else: if i + 1 == len(info_list): print("[ERROR_6]: no such person found, please re-enter!") break else: i += 1 else: print("[ERROR_7]: administrator account or password error, please re-enter!") def del_info(c): # Delete function, called when the parameter is a subsequent operation info_dic = find_info(3) if info_dic in info_list: info_list.remove(info_dic) if c == 2: print("[INFO_4]: deletion successful!") else: pass else: return False def alter_info(): # Modify the function if del_info(4) is False: pass else: print("[INFO_5]: please enter modified employee information!") print("-" * 30) # Separation line add_info(4) def verify(): # Administrator authentication function id_input = str(input("Please enter the administrator account number:")) pd_input = str(input("Please enter the administrator password:")) print("-" * 30) # Separation line if id_input == admin_id and pd_input == password: return True else: return False if command == 1: add_info(1) elif command == 2: find_info(2) elif command == 3: del_info(2) elif command == 4: alter_info() elif command == 5: if verify(): # equivalent to temp = verify() # if temp is True. print(info_list) else: print("[ERROR_8]: administrator account or password error, please re-enter!") elif command == 6: print("[INFO_6]: thanks for using it, you have successfully exited the system!") exit() else: print("[ERROR_9]: input error, please re-enter!")
This is the whole content of this article.