Python function to realize student management system


This example shares the specific code of Python function to realize the student management system for your reference. The specific contents are as follows

This is a simple management program

Enter name, age, gender (you can also add other categories, such as sexual orientation), and then save it as a list (empty list by default). The functions are as follows:

  • Press 1 to add members
  • Press 2 to delete the member
  • Press 3 to modify the member information (name is not included at present, but can be added)
  • Press 4 to retrieve and print all information about a member
  • Press 5 to print the information of all members
  • Press 6 to exit the program

That’s about it. Here is the code:

import time

def main():
  '' main function '' '
  while True:
    user_input = input('select your operation: ')
    if   user_input == '1':
    elif user_input == '2':
    elif user_input == '3':
    elif user_input == '4':
    elif user_input == '5':
    elif user_input == '6':
      print('\n system quit.')
      sl(),print('\n plz enter correct number.')

def select_function():
  '' display system functions' ''
  print("\n1.add mbr\n2.delete mbr\n3.change info\
         \n4.check info\n5.prt\'l info\n6.exit sys\n")
def store_new_info():
  a = input('enter name: ').title()
  b = input('enter age: ').title()
  c = input('enter gender: ').title()
  return a,b,c

def add_op():
  '' add new person '' '
  name,age,gender = store_new_info()
  for i in all_info:
    if name == i['name'].strip():
      print(f'{name} is existed.retry plz')
    dict_inf = {}
    dict_inf['name']   = name
    dict_inf['age']    = age
    dict_inf['gender'] = gender
    print(f'{name} added.')

def delete_op():
  '' delete existing people '' '
  del_nam = input('type the name to del:').title()
  for i in all_info:
    if del_nam == i['name'].strip():
      sl(),print(f'{del_nam} is removed.')
    sl(),print(f'no {del_nam} in list now.')

def alter_op():
  '' modify existing person information '' '
  alter_nam = input('type the name who needs change: ').title()
  for i in all_info:
    if alter_nam != i['name'].strip():
      i['age'] = input('type new age: ')
      i['gender'] = input('type new gender: ')
    sl(),print(f'no {alter_nam} in list.')

def search_op():
  '' find information about a person '' '
  se_num = input('type name to search: ').strip().title()
  for i in all_info:
    if se_num != i['name'].strip():

def modify_op():
  '' unified name initials are capitalized and left justified '' '
  b = 0
  for i in range(len(all_info)): 
    a = len(all_info[i].get('name').strip())
    b = max(a,b)
  for i in range(len(all_info)):
    all_info[i]['name']   = all_info[i].get('name').strip().title().ljust(b,' ')
    all_info[i]['gender'] = all_info[i].get('gender').strip().title().ljust(6,' ')

def print_op():
  '' output all information of all characters' ''
  for i in all_info:

def sl():

all_info = []

Briefly explain:

  • Since there is no switch case statement in Python, if elif is used instead to realize the requirement of key selection function
  • The storage of information is realized by nesting lists and dictionaries, that is, in the format of [{}, {}, {}]. Each dictionary stores the information of a person.
  • Function modify_ Op () is to beautify the display and realize the output of the names of all members with equal length, capital letters and left alignment. For example, norn and Scotti, the latter has 6 characters and the former has 4 characters. In this way, norn will be supplemented by 6 characters with spaces. This is why strip () and title () are used in a large number of functions
  • Some codes are used to avoid bugs, such as excluding the influence of case (vert and vert), excluding the possibility of duplicate names, excluding errors caused by inputting characters other than 1-6 when selecting program functions, and excluding various dead cycles.
  • Since the program does not have the function of saving information to a text file, all information will disappear after exiting the program. Because I use Google’s cloud IDE, I don’t know how to write the path to save the file (/ gddrive / file. TXT?). So when your computer can be used, it will be added

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support developpaer.