Function application: student management system

Keywords: Python

1, System functions

  • Add trainees
  • Delete trainees
  • Modify student information
  • Query student information
  • Show college information
  • Exit system

2, Step analysis

1. Display function interface

2. User input function serial number

3. Perform different functions according to the input sequence number

while True:
    # 1,Display function interface
    info_print()
    # 2,User input function serial number
    i = int(input('Please select the function:'))
    # 3,Perform different functions according to the input sequence number
    if i==1:
        print('Add trainees')
        add_info()
    elif i==2:
        print('Delete trainees')
        delete_info()
    elif i == 3:
        print('Modify student information')
        modif_info()
    elif i == 4:
        print('Search cadets')
        search_info()
    elif i==5:
        print('Print all students')
        display_all()
    elif i==6:
        flag = input('Are you sure you want to exit? y/n')
        if flag=='y':
            print('Exit successfully')
            break
    else:
        print('Please input 1-6 Digital instructions within')

3, Function realization

1. The main interface displays info "print()

# Display function interface
def info_print():
    print('Please select the following functions:----------------')
    print('1: Add trainees')
    print('2: Delete trainees')
    print('3: Modify student information')
    print('4: Query student information')
    print('5: Show all student information')
    print('6: Exit system')
    print('-'*20)

2. Add student add? Info()

#Define global variables
info =[]
def add_info(): """Add trainees""" #input sid = input('Please enter student ID:') name = input('Please enter student name:') tel = input('Please enter the student phone number:') #Create student dictionary student={'sid': sid, 'name':name, 'tel':tel} # Check whether the student name exists. If it exists, an error will be reported global info for i in info: if student['name']==i['name']: print('The student already exists') return # Save student information info.append(student) print('Add success')

 

3. Delete info ()

def delete_info():
    """Delete trainees"""
    #input
    del_name = input('Please enter the name of the deleted student:')

    # Judge whether the trainees exist, delete and report no errors
    global info
    for i in info:
        if del_name == i['name']:
            info.remove(i)
            print('Delete successful')
            break
    else:
        print('The user does not exist')

4. Modify student information

def modif_info():
    """Modify student information"""
    #lookup
    modif_name = input('Please enter the name of the student to be modified:')

    # Check whether the student name exists. If it exists, an error will be reported
    global info
    for i in info:
        if modif_name == i['name']:
            tel = input('New phone number:')
            i['tel']=tel
            print('Modified success')
            break
    else:
        print('The user does not exist')

5. Search for students

def search_info():
    """Search cadets"""
    search_name = input('Please enter the name of the student you want to search:')

    #Judge whether it exists, output exists, and error is not reported
    global info
    for i in info:
        if search_name==i['name']:
            print(i)
            break
    else:
        print('The user does not exist')

6. Print all students

def display_all():
    """Print all students"""
    global info
    for i in info:
        print(i)

Posted by sidhumaharaj on Tue, 24 Mar 2020 08:42:09 -0700