Teach you how to use python to implement a student information management system

This article mainly introduces the use of python to implement the student information management system in detail. The sample code in the article is very detailed and has a certain reference value. Interested friends can refer to it.

The examples in this article share the specific code of python to realize the student information management system for your reference. The specific content is as follows

The development steps of the student management system:

1. Display the function menu of the student management system

2. Function options for receiving user input

3. Determine the function options entered by the user and complete related operations

The purpose of extracting function codes to functions:

Provide the reusability of function codes and reduce the redundancy of function codes.

# Student list, specifically responsible for managing each student's information 
student_list = [] 
  
  
# Display the function function of the student management system menu 
def show_menu(): 
  print("================= == Student Management System V1.0 ===================") 
  print("1. Add student") 
  print("2. Delete student") 
  print(" 3. Modify student information") 
  print("4. Query student information") 
  print("5. Display all student information") 
  print("6. Exit") 
  
  
# Add student function function 
def add_student(): 
  # Realize add Student function 
  name = input("Please input your name:") 
  age = input("Please input your age:") 
  sex = input("Please input your gender:") 
  # Each student information It is a dictionary type. You need to assemble these three items of data into the dictionary. 
  Student_dict = {"name": name, "age": age, "sex":sex} 
  # Add the student dictionary information to the list 
  student_list.append(student_dict) 
  
  
# Display the function function of all students
def show_all_student(): 
  # Realize the function of displaying all students 
  for index, student_dict in enumerate(student_list): 
    # Student ID = subscript + 1 
    student_no = index + 1 
    print("Student ID: %d Name: %s Age:% s Gender: %s"% (student_no, 
                        student_dict["name"], 
                        student_dict["age"], 
                        student_dict["sex"])) 
  
  
# Function function for deleting students 
def remove_student(): 
  # 1. Receive the student to be deleted Student ID 
  student_no = int(input("Please enter the student ID you want to delete:")) 
  # 2. Generate subscripts according to students 
  index = student_no-1 
  # Determine whether the subscripts are legal 
  if 0 <= index <len( student_list): 
    # 3. Delete the specified data from the list according to the subscript 
    student_dict = student_list.pop(index)
    print("%s, successfully deleted!"% student_dict["name"]) 
  else: 
    print("Please enter a valid student ID!") 
  
  
# Function function to modify student information 
def modify_student(): 
  # 1. Receive to modify Student ID 
  student_no = int(input("Please enter the student ID you want to modify:")) 
  # 2. According to the student to generate subscript 
  index = student_no-1 
  # Determine whether the subscript is legal 
  if 0 <= index <len (student_list): 
    # 3. Obtain the corresponding student dictionary information according to the subscript 
    modify_student_dict = student_list[index] 
    # 4. Modify the student information according to the dictionary 
    modify_student_dict["name"] = input("Please enter your modified name:") 
    modify_student_dict["age"] = input("Please enter your modified age:") 
    modify_student_dict["sex"] = input("Please enter your modified gender:") 
    print("Modified successfully") 
  else: 
    print("Please enter your legal student number!") 
  
  
# Check students
) #学生管理系统的发展步骤
# Tip: Since the system needs to be running all the time, you need to put the above three steps into an infinite loop, so that you can save the program to run all the time. 
# Define the entry function of the program, the first function to be executed in the program 
def start(): 
  # 1.The name of the student to be queried for receiving user 
  input name = input("Please enter the name of the student to be queried:")
  
  
  while True: 
    # 1.
    show_menu() 
    # 2. The function option that receives user input 
    menu_option = input("Please enter the function option you want to operate:") 
    # 3. Determine the function option input by the user and complete the related operation 
    if menu_option == "1" : 
      print("Add student") 
      add_student() 
    elif menu_option == "2": 
      print("Delete student") 
      remove_student() 
    elif menu_option == "3": 
      print("Modify student information") 
      modify_student() 
    elif menu_option == "4": 
      print("Query student information") 
      query_student() 
    elif menu_option == "5": 
      print("Display all student information") 
      show_all_student() 
    elif menu_option == "6":
      print("Exit") 
      break
  
  
# Start the program 
start()

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Guess you like

Origin blog.csdn.net/yaxuan88521/article/details/114627692
Recommended