Student management system (improved version)

'''

Environment: Python3.6.4 to
write "Student Management System" (improved version), the initial requirements are as follows: You
must use custom functions to complete the modularization of the program
Student confidence at least includes: name, age, student number, other than this can be appropriately added
Functions that must be completed: add, delete, modify, query, traverse, exit
'''

#Define a list to store the information of multiple students
stuList = []

#Define the system menu display function
def displayMenu(): #Complete
  the function of displaying the system menu
  print("*"*40)
  print("Student Management System V2.0")
  print(" 1. Add student information")
  print(" 2. Delete student information")
  print(" 3. Modify student information")
  print(" 4. Query student information")
  print(" 5. Traverse student information")
  print(" 6. Exit the student management system")
  print( "*"*40)

def addNewStu(): #Complete
  the function of adding student information
  name = input("Please enter the student's name:")
  stuId = input("Please enter the student's student number:")
  age = input("Please enter the student's age: ") #Define

  a dictionary to store the information of each student
  stuDict = {}
  stuDict['name'] = name
  stuDict['stuId'] = stuId
  stuDict['age'] = age

  global stuList
  # Put each student's Add information to the list
  stuList.append(stuDict)

def delStu():
  global stuList #Complete
  the function of deleting student information
  delName = input("Please enter the name of the student you want to delete: ")
  delFlag = 0
  for tempStu in stuList:
    if delName == tempStu['name']:
      delNum = stuList.index(tempStu) #Get the index of the student to be deleted in the list
      del stuList[delNum] #Delete by index
      delFlag = 1 #Delete successful
      break
  if delFlag == 0:
    print("There is no such person, please try again enter!")

def reviseStu():
  global stuList #Complete
  the function of modifying student information
  reviseName = input("Please enter the name of the student whose information you want to modify: ")
  reviseFlag = 0
  for tempStuDict in stuList:
    if reviseName == tempStuDict['name']: #Modify
      student information
      newStuId = input("Please enter the student ID of the student to be modified:")
      newAge = input("Please enter the age of the student to be modified:")
      tempStuDict['stuId'] = newStuId
      tempStuDict['age '] = newAge
      reviseFlag = 1
      break
  if reviseFlag == 0:
    print("No such person, please re-enter!")

def inquireStu():
  global stuList #Complete
  the function of querying student information
  inquireName = input("Please enter what you want The name of the queried student: ")
  inquireFlag = 0
  for temp in stuList:
    if inquireName == temp['name']:
      print("%s\t%s\t%s"%(temp['name'], temp['stuId'], temp['age']))
      inquireFlag = 1 #Indicates that the query is successful
      break
  if inquireFlag == 0:
    print("There is no such person...")

def bianliStu(): #Complete
  the function of traversing student information
  print("Name\tStudent ID\tAge")
  for tempStu in stuList:
  print("%s\t%s\t%s"%(tempStu['name'], tempStu['stuId'], tempStu['age']))


def main(): #Menu
  display
  #1. Prompt the user to select the function
  displayMenu()

  while True:
    #2. Get the user's input
    key = int(input("Please enter the function number of your choice: "))

    if key == 1:
      addNewStu()
    elif key == 2:
      delStu()
    elif key == 3:
      reviseStu()
    elif key == 4:
      inquireStu()
    elif key == 5:
      bianliStu()
    elif key == 6:
      ssmu = input ("Dear, do you really want to quit? (y/n) ~~~~>_<~~~~")
    if ssmu == 'y':
      break
    else:
      print("The input is incorrect, please re-enter!" )

    print("")

#Call the main function
main()

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325113661&siteId=291194637