基于函数和文件操作的学生管理系统

源代码

"""__author__ == Jefferson"""
import json
try:
    with open('./StudentInfomation.json','r',encoding='utf-8') as file:
        stu_info = json.load(file)
except:
    file = open('./StudentInfomation.json','w')
    file.close()
    stu_info = {'stuid':0}

operater = ''#预设操作人员

#主菜单函数
def menu():
    while True:
        if operater != '':#判断是否登陆成功
            global stu
            stu = stu_info[operater]#读取操作人员账号下的信息
            print('\tStudent Management\t'.center(36,'*'))
            print('**'+'\t1. Add Student\t'.center(34,' ')+' **')
            print('**' + '\t2. Search Student'.center(34, ' ') + ' **')
            print('**' + '\t3. Alter Student\t'.center(29, ' ') + ' **')
            print('**' + '\t        4. Grades Of Students\t'.center(32, ' ') + ' **')
            print('**' + '\t5. Delete Student'.center(34, ' ') + ' **')
            print('**' + '\t6. Quit          '.center(34, ' ') + ' **')
            print('*'*40)
            while True:
                n = input('Please input operation number:')
                if n == '1':
                    add_stu()
                elif n == '2':
                    find_stu()
                elif n == '3':
                    alter()
                elif n == '4':
                    grades_ctrl()
                elif n == '5':
                    delete()
                elif n == '6':
                    stu_info[operater] = stu
                    with open('./StudentInfomation.json', 'w') as file:
                        json.dump(stu_info,file)
                    exit()
                else:
                    print('please input a legal order!')
        else:#未登录或登陆不成功则显示登陆注册界面
            print('\tStudent Management\t'.center(36, '*'))
            print('**' + '\t1. Login         '.center(34, ' ') + ' **')
            print('**' + '\t2. Regist        '.center(34, ' ') + ' **')
            print('**' + '\t3. Quit          '.center(34, ' ') + ' **')
            print('*' * 40)
            while True:
                n = input('please input operation number:')
                if n == '1':
                    login()#调用登陆函数
                elif n == '2':
                    regist()#调用注册函数
                elif n == '3':#退出前存入信息到文件,此处主要作用是注册用户成功但并未登陆保存已注册的帐户
                    with open('.\StudentInfomation.json', 'w') as file:
                        json.dump(stu_info, file)
                    exit()
                else:
                    print('please input a legal order!')
#登陆判断
def login():
    global operater
    print('please login!')
    user_name = input('username:')
    password = input('password:')
    if stu_info.get(user_name):#判断用户名是否存在
        if password == stu_info[user_name]['password']:#验证用户名对应的密码是否正确
            operater = user_name#对当前操作人员进行赋值
            print('login success!')
        else:
            print('password error!')
    else:
        print("username don't exist")
    menu()
#注册账号
def regist():
    print('regist!')
    user_name = input('username:')
    password = input('password:')
    if stu_info.get(user_name) == None:#判断账户名是否已存在
        stu_info[user_name] = {}#写入到帐户序列
        stu_info[user_name]['password'] = password
        print('regist success!')
    else:
        print('this username has been registed!')
    menu()
#更新成绩
def update_grades(stu_id):
    if stu.get(stu_id) != None:#判断stu_id是否存在
        count = 0#用于统计录入成绩成功的数量
        grades = {'English': '0', 'Gym': '0', 'Art': '0', 'Math': '0'}#各科成绩默认为0
        print('Please input the Grades!\n<%s>'%(stu_id))
        grd_eng = input('English:')
        grd_math = input('Math::')
        grd_art = input('Gym:')
        grd_gym = input('Art:')
        #判断各科成绩是否合法
        if grd_eng.isdigit() and 0 <= int(grd_eng) <= 100:
            grades['English'] = grd_eng
            count += 1
        if grd_gym.isdigit() and 0 <= int(grd_gym) <= 100:
            grades['Gym'] = grd_gym
            count += 1
        if grd_art.isdigit() and 0 <= int(grd_art) <= 100:
            grades['Art'] = grd_art
            count += 1
        if grd_math.isdigit() and 0 <= int(grd_math) <= 100:
            grades['Math'] = grd_math
            count += 1
        if count == 4:#如果所有成绩都成功录入则提示录入成功
            stu[stu_id]['grades'] = grades
            print('the grades of student<%s, %s>update success!'%(stu[stu_id]['name'],stu_id))
        else:#如果有成绩不合法则提示是否重新录入,否则不合法的成绩则默认为0
            print('some grades are illegal, it will be 0 unless you readd it!')
            while True:
                n2 = input('1. Readd grades for this student\n2. let it pass\nplease input operation number:')
                if n2 == '1':
                    update_grades(stu_id)
                    break
                elif n2 == '2':
                    break
                else:
                    print('please input a legal order!')
    else:
        print('The student number dose not exit!')
#添加学生
def add_stu():
    stuid = stu_info['stuid']#识别当前学号序号的值,用于生成学号时接着已存在的最大序号后面
    stuid += 1#确定本次添加学生的学号序号
    global stu
    info = {}#声明一个空字典用于存放本次添加学生的信息
    stu_id = 'Python1805'+str(stuid).rjust(4,'0')#生成学号
    print('add student!')
    stu_name = input('name:')
    while True:#性别选择,限male或者female
        stu_sex = input('please choose sex(1 or 2):\n\t1. male\n\t2. female\n>>>')
        if stu_sex == '1':
            stu_sex = 'male'
            break
        elif stu_sex == '2':
            stu_sex = 'female'
            break
        else:
            continue
    stu_age = input('age:')
    stu_tel = input('tel:')
    info['name'] = stu_name
    info['sex'] = stu_sex
    info['age'] = stu_age
    info['tel'] = stu_tel
    stu[stu_id] = info#将学生的基本信息添加到字典中并以学号为键
    grades = {'English': '0', 'Math': '0', 'Art': '0', 'Gym': '0'}
    stu[stu_id]['grades'] = grades#将默认成绩为0的成绩字典添加到该学生的信息中
    stu_info['stuid'] = stuid#将本次的学号序号存入外层字典中用以下次添加学生的学号判断依据
    while True:
        print('add base information success!')
        print('1. Continue to add grades to the students')
        print('2. Continue to add another students')
        print('3. Return homepage')
        n1 = input('>>>')
        if n1 == '1':
            update_grades(stu_id)
            while True:
                print('1. Continue to add another students')
                print('2. Return homepage')
                n1 = input('>>>')
                if n1 == '1':
                    add_stu()
                elif n1 == '2':
                    menu()
                else:
                    print('please input')
        elif n1 == '2':
            add_stu()
        elif n1 == '3':
            menu()
        else:
            print('please input a legal order!')
#找到所有的学生信息并显示
def find_all(grd,avg):
    print('\nSearch Result:')
    if grd == True:#判断是否显示成绩表头
        print('Student_Number'.ljust(16) + '\t', 'Name'.ljust(8) + '\t',
              'English'.ljust(5) + '\t', 'Math'.ljust(8) + '\t',
              'Art'.ljust(10) + '\t', 'Gym'.ljust(12), end='')
        if avg == True:#判断显示成绩的同时是否显示平均成绩表头
            english_sum = 0
            math_sum = 0
            art_sum = 0
            gym_sum = 0
            print('Average_Grades')
        else:
            print()
    else:
        print('student_number'.ljust(16) + '\t', 'Name'.ljust(8) + '\t',
              'Sex'.ljust(5) + '\t', 'Age'.ljust(5) + '\t', 'Tel'.ljust(11) + '\t')
    #将所有操作人员下的学生学号提取出来遍历备用, 并将备用列表中的密码字段删除,防止遍历时学生字典下标不存在(学号对应的是一个学生字典,而密码对应的是一个字符串)
    keys = list(stu.keys())
    for index in range(0,len(keys)):
        if keys[index] == 'password':
            del keys[index]
            break
    #先将学号列表进行排序
    keys.sort()
    for k in keys:
        if grd == True:#判段是否显示成绩数据
            print(k.ljust(16)+'\t',stu[k]['name'].ljust(8)+'\t',
                  stu[k]['grades']['English'].ljust(9)+'\t',
                  stu[k]['grades']['Math'].ljust(8)+'\t',
                  stu[k]['grades']['Art'].ljust(10)+'\t',
                  stu[k]['grades']['Gym'].ljust(8)+'\t', end='')
            if avg == True:#判断显示成绩的同时是否显示平均成绩
                english_sum += float(stu[k]['grades']['English'])
                math_sum += float(stu[k]['grades']['Math'])
                art_sum += float(stu[k]['grades']['Art'])
                gym_sum += float(stu[k]['grades']['Gym'])
                print('',(float(stu[k]['grades']['English'])+float(stu[k]['grades']['Math'])\
                       +float(stu[k]['grades']['Art'])+float(stu[k]['grades']['Gym']))/len(stu[k]['grades']))
            else:
                print()
        else:#显示基本信息
            print(k.ljust(16) + '\t', stu[k]['name'].ljust(8) + '\t',
                  stu[k]['sex'].ljust(5) + '\t', stu[k]['age'].ljust(5) + '\t',
                  stu[k]['tel'].ljust(14) + '\t')
    if avg == True:#如果显示平均成绩的话则显示整个班的平均成绩
        print('\n','Class'.ljust(16) + '\t', 'Students'.ljust(8) + '\t',
              'Average'.ljust(5) + '\t', 'Average'.ljust(5) + '\t',
              'Average'.ljust(5) + '\t', 'Average'.ljust(5) + '\t',
              'Average'.ljust(5))
        if len(keys) != 0:
            print(keys[0][0:10].ljust(16) + '\t', str(len(keys)).ljust(8) + '\t',
                  ('%.2f' %(english_sum/len(keys))).ljust(9)+'\t',
                  ('%.2f' %(math_sum/len(keys))).ljust(9) + '\t',
                  ('%.2f' %(art_sum/len(keys))).ljust(9) + '\t',
                  ('%.2f' %(gym_sum/len(keys))).ljust(9) + '\t',
                  ('%.2f' %(((english_sum+math_sum+art_sum+gym_sum)/len(keys))/4)).ljust(5))
    return len(keys)
#通过学生姓名查找学生
def find_by_name(grd,avg,stu_name = ''):
    count = 0#声明数量统计变量
    if stu_name == '':#如果未传入姓名则要求输入
        stu_name = input('Please input the name of the student:')
    print('\nSearch Result:')

    if grd == True:#判断是否显示成绩
        print('Student_Number'.ljust(16) + '\t','Name'.ljust(8) + '\t',
              'English'.ljust(5) + '\t', 'Math'.ljust(8) + '\t',
              'Art'.ljust(10) + '\t', 'Gym'.ljust(12), end='')
        if avg == True:#判断显示成绩的同时是否显示平均成绩
            print('Average_Grades')
        else:
            print()
    else:#显示基本信息
        print('Student_Number'.ljust(16) + '\t', 'Name'.ljust(8) + '\t',
              'Sex'.ljust(5) + '\t', 'Age'.ljust(5) + '\t',
              'Tel'.ljust(11) + '\t')
    for k in stu:#遍历查找指定名字的学生
        if k != 'password' and stu[k]['name'] == stu_name:
            if grd == True:#判断是否显示成绩数据
                print(k.ljust(16) + '\t', stu[k]['name'].ljust(8) + '\t',
                      stu[k]['grades']['English'].ljust(9) + '\t',
                      stu[k]['grades']['Math'].ljust(8) + '\t',
                      stu[k]['grades']['Art'].ljust(10) + '\t',
                      stu[k]['grades']['Gym'].ljust(8) + '\t', end='')
                if avg == True:#判断显示成绩的同时是否显示平均成绩
                    print('',(float(stu_info[operater][k]['grades']['English']) + \
                           float(stu_info[operater][k]['grades']['Math']) +\
                           float(stu_info[operater][k]['grades']['Art']) + \
                           float(stu_info[operater][k]['grades']['Gym'])) / len(stu[k]['grades']))
                else:
                    print()
            else:#显示基本信息
                print(k.ljust(16) + '\t', stu[k]['name'].ljust(8) + '\t', stu[k]['sex'].ljust(5) + '\t',
                      stu[k]['age'].ljust(5) + '\t', stu[k]['tel'].ljust(14) + '\t')
            count += 1#统计查找姓名的学生数量
            stu_id = k#存放最后找到的学生学号
    if count == 0:#如果为找到学生则提示并返回None
        print('No information about the student was found!')
    else:
        return count,stu_name,stu_id
#通过学号查找学生
def find_by_id(grd,avg,stu_id = ''):
    count = 0#计数判断是否找到该学生
    if stu_id == '':#如果为传入学号则要求输入
        stu_id = input('Please input the student number:')
    print('\nSearch Result:')

    if grd == True:#判断是否显示学生成绩
        print('Student_Number'.ljust(16) + '\t', 'Name'.ljust(8) + '\t',
              'English'.ljust(5) + '\t', 'Math'.ljust(8) + '\t',
              'Art'.ljust(10) + '\t', 'Gym'.ljust(12), end='')
        if avg == True:#判读显示成绩的同时是否显示平均成绩
            print('Average_Grades')
        else:
            print()
    else:
        print('Student_Number'.ljust(16) + '\t', 'Name'.ljust(8) + '\t',
              'Sex'.ljust(5) + '\t', 'Age'.ljust(5) + '\t',
              'Tel'.ljust(11) + '\t')
    for k in stu:
        if k == stu_id:
            if grd == True:#判断是否显示成绩
                print(k.ljust(16) + '\t', stu[k]['name'].ljust(8) + '\t',
                      stu[k]['grades']['English'].ljust(9) + '\t',
                      stu[k]['grades']['Math'].ljust(8) + '\t',
                      stu[k]['grades']['Art'].ljust(10) + '\t',
                      stu[k]['grades']['Gym'].ljust(8) + '\t', end='')
                if avg == True:#判读显示成绩的同时是否显示平均成绩
                    print('',(float(stu_info[operater][k]['grades']['English']) + \
                           float(stu_info[operater][k]['grades']['Math']) + \
                           float(stu_info[operater][k]['grades']['Art']) + \
                           float(stu_info[operater][k]['grades']['Gym'])) / len(stu[k]['grades']))
                else:
                    print()
            else:#显示基本信息
                print(k.ljust(16) + '\t', stu[k]['name'].ljust(8) + '\t', stu[k]['sex'].ljust(5) + '\t',
                      stu[k]['age'].ljust(5) + '\t', stu[k]['tel'].ljust(14) + '\t')
            count += 1
    if count == 0:#如果为找到该学生则输出提示并返None
        print('No information about the student was found!')
    else:#找到学生则返回学号
        return stu_id
#查找学生
def find_stu():
    while True:
        print('\n1. Search all student information')
        print('2. Search by student name')
        print('3. Search by student number')
        print('4. Return homepage')
        n1 = input('>>>')
        if n1 == '1':
            find_all(False,False)
        elif n1 == '2':
           find_by_name(False,False)
        elif n1 == '3':
            find_by_id(False,False)
        elif n1 == '4':
            menu()
        else:
            print('please input a legal order!')
#修改学生信息
def alter():
    stu_id = find_by_id(False, False)
    if stu_id != None:#判断学号是否存在
        #读入所有原本的数据
        stu_name = stu[stu_id]['name']
        stu_sex = stu[stu_id]['sex']
        stu_age = stu[stu_id]['age']
        stu_tel = stu[stu_id]['tel']
        print('\n1. Alter name for this student')
        print('2. Alter age for this student')
        print('3. Alter sex for this student')
        print('4. Alter tel for this student')
        print('5. Alter all base information for this student')
        print('6. Return homepage')
        while True:
            n1 = input('>>>')
            if n1 == '1':#输入名字
                stu_name = input('please input new name:')
                break
            elif n1 == '2':#输入年龄
                stu_age = input('please input new age:')
                break
            elif n1 == '3':#输入性别
                stu_sex = 'male' if stu[stu_id]['sex'] == 'female' else 'female'
                print('%s -> %s'%(stu[stu_id]['sex'],stu_sex))
                break
            elif n1 == '4':#输入电话
                stu_tel = input('please input new tel:')
                break
            elif n1 == '5':#输入所有基本信息
                stu_name = input('name:')
                while True:
                    stu_sex = input('please choose sex(1 or 2):\n\t1. male\n\t2. female\n>>>')
                    if stu_sex == '1':
                        stu_sex = 'male'
                        break
                    elif stu_sex == '2':
                        stu_sex = 'female'
                        break
                    else:
                        continue
                stu_age = input('age:')
                stu_tel = input('tel:')
                break
            elif n1 == '6':
                menu()
            else:
                print('please input a legal order!')
        print('alter success!')
        print('1. Continue to alter another')
        print('2. Rpeal the alter just now and return homepage')
        print('3. Return home page')
        while True:
            n = input('>>>')
            if n == '1':#继续添加则保存已修改的数据
                stu[stu_id]['name'] = stu_name
                stu[stu_id]['sex'] = stu_sex
                stu[stu_id]['age'] = stu_age
                stu[stu_id]['tel'] = stu_tel
                alter()
            elif n == '2':#撤销并返回主菜单则不保存修改的数据
                menu()
            elif n == '3':#返回主菜单则保存已修改的数据
                stu[stu_id]['name'] = stu_name
                stu[stu_id]['sex'] = stu_sex
                stu[stu_id]['age'] = stu_age
                stu[stu_id]['tel'] = stu_tel
                menu()
            else:
                print('please input a legal order!')
    else:#如果为找到学生则提示返回或者继续查找
        while True:
            n = input('1. Search again\n2. Return homepage\n>>>')
            if n == '1':
                alter()
            if n == '2':
                menu()
            else:
                print('please input a legal order!')
#成绩操作
def grades_ctrl():
    while True:
        print('\nGrades Of Students')
        print('1. Search all student grades')
        print('2. Search by student name')
        print('3. Search by student number')
        print('4. Return homepage')
        n1 = input('>>>')
        if n1 == '1':
            find_all(True, False)#查找并显示所有的学生,显示成绩
            while True:
                print('\n1. Show average performance')
                print('2. Revise the grades of all the students')
                print("3. Revise one of the students' grades")
                print('4. Back')
                print('5. Return homepage')
                n2 = input('>>>')
                if n2 == '1':#显示平均成绩
                    find_all(True,True)
                elif n2 == '2':#修改所有的学生的成绩
                    keys = list(stu.keys())
                    for index in range(0, len(keys)):
                        if keys[index] == 'password':
                            del keys[index]
                            break
                    keys.sort()
                    for k in keys:
                        update_grades(k)
                        find_by_id(True,True,k)
                        print('student<%s %s> update grades success!'%(k,stu[k]['name']))
                        print('1. Continue update next\n2. Back')
                        while True:#每修改一个学生就提示继续或者停止修改返回
                            n3 = input('>>>')
                            if n3 == '1':
                                break
                            elif n3 == '2':
                                break
                            else:
                                print('please input a legal order!')
                        if n3 == '2':
                            break
                elif n2 == '3':#修改指定学生的成绩
                    stu_id = find_by_id(True,False)
                    if stu_id != None:
                        update_grades(stu_id)
                        break
                    else:
                        print('The student does not exist!')
                elif n2 == '4':
                    grades_ctrl()
                elif n2 == '5':
                    menu()
                else:
                    print('please input a legal order!')
        elif n1 == '2':#通过名字查看学生成绩
            name_info = find_by_name(True, True)
            if name_info != None:
                while True:
                    print("\n1. Revise the students' grades")
                    print('2. Back')
                    print('3. Return homepage')
                    n2 = input('>>>')
                    if n2 == '1':#修改该名字学生成绩
                        if name_info[0] > 1:#如果有多个学生同名则提示通过学号修改
                            print('There are more than one student named %s!'%(name_info[1]))
                            stu_id = input('please input student number to revise:')
                            update_grades(stu_id)
                        else:
                            update_grades(name_info[2])
                        break
                    elif n2 == '2':
                        break
                    elif n2 == '3':
                        menu()
                    else:
                        print('please input a legal order!')
            else:
                print('There is no student named that you input!')
        elif n1 == '3':#通过学号查看学生成绩
            stu_id = find_by_id(True, True)
            if stu_id != None:
                while True:
                    print("\n1. Revise the students' grades")
                    print('2. Back')
                    print('3. Return homepage')
                    n2 = input('>>>')
                    if n2 == '1':#修改查到的学生的成绩
                        update_grades(stu_id)
                        break
                    elif n2 == '2':
                        break
                    elif n2 == '3':
                        menu()
                    else:
                        print('please input a legal order!')
            else:
                print('The student number you input dose not exit!')
        elif n1 == '4':
            menu()
        else:
            print('please input a legal order!')
#删除学生
def delete():
    while True:
        print('1. Delete by student number')
        print('2. Delete by name')
        print('3. Deldte all')
        print('4. Return homepage')
        n = input('>>>')
        if n == '1':#通过学号删除学生
            stu_id = find_by_id(False,False)
            if stu_id != None:#确认是否删除该学生
                print('1. Confirm Delete\n2. Back')
                n1 = input('>>>')
                if n1 == '1':
                    del stu[stu_id]
                    print('delete<%s> success!'%(stu_id))
                elif n1 == '2':
                    pass
            else:
                print('The student number you input dose not exit!')
        elif n == '2':#通过姓名删除学生
            count = 0
            name_info = find_by_name(False,False)
            if name_info != None:#如果找到该名字的学生
                while True:
                    print("\n1. Delete all student that named %s"%(name_info[1]))
                    print('2. Delete by student number')
                    print('3. Back')
                    n2 = input('>>>')
                    if n2 == '1':#直接删除所有该名字的学生
                        while count != name_info[0]:
                            for k in stu:
                                if k != 'password' and stu[k]['name'] == name_info[1]:
                                    del stu[k]
                                    count += 1
                                    break
                        print('All the student named %s has been deleted!'%(name_info[1]))
                        break
                    elif n2 == '2':#通过学号删除学生
                        stu_id = find_by_id(False, False)
                        if stu_id != None:
                            while True:
                                print('1. Confirm Delete\n2. Back')
                                n1 = input('>>>')
                                if n1 == '1':
                                    del stu[stu_id]
                                    print('delete<%s> success!' % (stu_id))
                                    break
                                elif n1 == '2':
                                    break
                                else:
                                    print('please input a legal order!')
                        else:
                            print('The student number you input dose not exit!')
                    elif n2 == '3':
                        break
                    else:
                        print('please input a legal order!')
            else:
                print('There is no student named that you input!')
        elif n == '3':#删除该操作人员帐号所有的学生
            count = find_all(False,False)
            if count == 0:
                print('There is no student!')
            else:
                while True:#确认界面
                    print('1. Confirm Delete\n2. Back')
                    n1 = input('>>>')
                    if n1 == '1':
                        while count != 0:
                            for k in stu:
                                if k != 'password':
                                    del stu[k]
                                    count -= 1
                                    break
                        print('All student have been deleted!')
                        break
                    elif n1 == '2':
                        break
                    else:
                        print('please input a legal order!')
        elif n == '4':#回到主菜单
            menu()
        else:
            print('please input a legal order!')

if __name__ == '__main__':
    menu()

运行测试

E:\Python\Python37\python.exe D:/PSL/study/Python/Workplace/train/day09文件操作/StudentManagement/StudentManagement.py
********    Student Management  ********
**          1. Login                  **
**          2. Regist                 **
**          3. Quit                   **
****************************************
please input operation number:4
please input a legal order!
please input operation number:2
regist!
username:1
password:1
this username has been registed!
********    Student Management  ********
**          1. Login                  **
**          2. Regist                 **
**          3. Quit                   **
****************************************
please input operation number:2
regist!
username:2
password:2
regist success!
********    Student Management  ********
**          1. Login                  **
**          2. Regist                 **
**          3. Quit                   **
****************************************
please input operation number:1
please login!
username:1
password:1
login success!
********    Student Management  ********
**          1. Add Student            **
**          2. Search Student         **
**          3. Alter Student          **
**          4. Grades Of Students     **
**          5. Delete Student         **
**          6. Quit                   **
****************************************
Please input operation number:7
please input a legal order!
Please input operation number:1
add student!
name:Tom
please choose sex(1 or 2):
    1. male
    2. female
>>>1
age:23
tel:342341232
add base information success!
1. Continue to add grades to the students
2. Continue to add another students
3. Return homepage
>>>4
please input a legal order!
add base information success!
1. Continue to add grades to the students
2. Continue to add another students
3. Return homepage
>>>2
add student!
name:Jack
please choose sex(1 or 2):
    1. male
    2. female
>>>1
age:21
tel:43124234
add base information success!
1. Continue to add grades to the students
2. Continue to add another students
3. Return homepage
>>>1

Please input the Grades!
<Python18050008>
English:Math::
Gym:
Art:
some grades are illegal, it will be 0 unless you readd it!
1. Readd grades for this student
2. let it pass
please input operation number:1
Please input the Grades!
<Python18050008>
English:89
Math::778
Gym:78
Art:87
some grades are illegal, it will be 0 unless you readd it!
1. Readd grades for this student
2. let it pass
please input operation number:1
Please input the Grades!
<Python18050008>
English:89
Math::87
Gym:88
Art:76
the grades of student<Jack, Python18050008>update success!
1. Continue to add another students
2. Return homepage
>>>4
please input
1. Continue to add another students
2. Return homepage
>>>2
********    Student Management  ********
**          1. Add Student            **
**          2. Search Student         **
**          3. Alter Student          **
**          4. Grades Of Students     **
**          5. Delete Student         **
**          6. Quit                   **
****************************************
Please input operation number:2

1. Search all student information
2. Search by student name
3. Search by student number
4. Return homepage
>>>1

Search Result:
student_number       Name        Sex     Age     Tel            
Python18050001       Jefferson   male    21      13096096557    
Python18050002       Tom         male    20      17608175671    
Python18050003       Alice       female  21      3161530        
Python18050004       Lucy        female  20      132455343      
Python18050005       Tom         male    21      6456543453     
Python18050007       Tom         male    23      342341232      
Python18050008       Jack        male    21      43124234       

1. Search all student information
2. Search by student name
3. Search by student number
4. Return homepage
>>>2
Please input the name of the student:tom

Search Result:
Student_Number       Name        Sex     Age     Tel            
No information about the student was found!

1. Search all student information
2. Search by student name
3. Search by student number
4. Return homepage
>>>2
Please input the name of the student:Tom

Search Result:
Student_Number       Name        Sex     Age     Tel            
Python18050002       Tom         male    20      17608175671    
Python18050005       Tom         male    21      6456543453     
Python18050007       Tom         male    23      342341232      

1. Search all student information
2. Search by student name
3. Search by student number
4. Return homepage
>>>3
Please input the student number:python18050001

Search Result:
Student_Number       Name        Sex     Age     Tel            
No information about the student was found!

1. Search all student information
2. Search by student name
3. Search by student number
4. Return homepage
>>>3
Please input the student number:Python18050001

Search Result:
Student_Number       Name        Sex     Age     Tel            
Python18050001       Jefferson   male    21      13096096557    

1. Search all student information
2. Search by student name
3. Search by student number
4. Return homepage
>>>5
please input a legal order!

1. Search all student information
2. Search by student name
3. Search by student number
4. Return homepage
>>>4
********    Student Management  ********
**          1. Add Student            **
**          2. Search Student         **
**          3. Alter Student          **
**          4. Grades Of Students     **
**          5. Delete Student         **
**          6. Quit                   **
****************************************
Please input operation number:3
Please input the student number:Pytho

Search Result:
Student_Number       Name        Sex     Age     Tel            
No information about the student was found!
1. Search again
2. Return homepage
>>>3
please input a legal order!
1. Search again
2. Return homepage
>>>1
Please input the student number:Python18050007

Search Result:
Student_Number       Name        Sex     Age     Tel            
Python18050007       Tom         male    23      342341232      

1. Alter name for this student
2. Alter age for this student
3. Alter sex for this student
4. Alter tel for this student
5. Alter all base information for this student
6. Return homepage
>>>1
please input new name:Mike
alter success!
1. Continue to alter another
2. Rpeal the alter just now and return homepage
3. Return home page
>>>1
Please input the student number:Python18050007

Search Result:
Student_Number       Name        Sex     Age     Tel            
Python18050007       Mike        male    23      342341232      

1. Alter name for this student
2. Alter age for this student
3. Alter sex for this student
4. Alter tel for this student
5. Alter all base information for this student
6. Return homepage
>>>2
please input new age:20
alter success!
1. Continue to alter another
2. Rpeal the alter just now and return homepage
3. Return home page
>>>2
********    Student Management  ********
**          1. Add Student            **
**          2. Search Student         **
**          3. Alter Student          **
**          4. Grades Of Students     **
**          5. Delete Student         **
**          6. Quit                   **
****************************************
Please input operation number:2

1. Search all student information
2. Search by student name
3. Search by student number
4. Return homepage
>>>1

Search Result:
student_number       Name        Sex     Age     Tel            
Python18050001       Jefferson   male    21      13096096557    
Python18050002       Tom         male    20      17608175671    
Python18050003       Alice       female  21      3161530        
Python18050004       Lucy        female  20      132455343      
Python18050005       Tom         male    21      6456543453     
Python18050007       Mike        male    23      342341232      
Python18050008       Jack        male    21      43124234       

1. Search all student information
2. Search by student name
3. Search by student number
4. Return homepage
>>>4
********    Student Management  ********
**          1. Add Student            **
**          2. Search Student         **
**          3. Alter Student          **
**          4. Grades Of Students     **
**          5. Delete Student         **
**          6. Quit                   **
****************************************
Please input operation number:3
Please input the student number:Python18050007

Search Result:
Student_Number       Name        Sex     Age     Tel            
Python18050007       Mike        male    23      342341232      

1. Alter name for this student
2. Alter age for this student
3. Alter sex for this student
4. Alter tel for this student
5. Alter all base information for this student
6. Return homepage
>>>5
name:Tom
please choose sex(1 or 2):
    1. male
    2. female
>>>1
age:23
tel:4562455
alter success!
1. Continue to alter another
2. Rpeal the alter just now and return homepage
3. Return home page
>>>3
********    Student Management  ********
**          1. Add Student            **
**          2. Search Student         **
**          3. Alter Student          **
**          4. Grades Of Students     **
**          5. Delete Student         **
**          6. Quit                   **
****************************************
Please input operation number:4

Grades Of Students
1. Search all student grades
2. Search by student name
3. Search by student number
4. Return homepage
>>>1

Search Result:
Student_Number       Name        English     Math        Art         Gym         
Python18050001       Jefferson   99          98          99          97         
Python18050002       Tom         89          98          78          87         
Python18050003       Alice       0           0           0           0          
Python18050004       Lucy        0           0           0           0          
Python18050005       Tom         90          98          78          98         
Python18050007       Tom         0           0           0           0          
Python18050008       Jack        89          87          88          76         

1. Show average performance
2. Revise the grades of all the students
3. Revise one of the students' grades
4. Back
5. Return homepage
>>>1

Search Result:
Student_Number       Name        English     Math        Art         Gym         Average_Grades
Python18050001       Jefferson   99          98          99          97          98.25
Python18050002       Tom         89          98          78          87          88.0
Python18050003       Alice       0           0           0           0           0.0
Python18050004       Lucy        0           0           0           0           0.0
Python18050005       Tom         90          98          78          98          91.0
Python18050007       Tom         0           0           0           0           0.0
Python18050008       Jack        89          87          88          76          85.0

 Class               Students    Average     Average     Average     Average     Average
Python1805           7           52.43       54.43       49.00       51.14       51.75

1. Show average performance
2. Revise the grades of all the students
3. Revise one of the students' grades
4. Back
5. Return homepage
>>>3
Please input the student number:Python18050003

Search Result:
Student_Number       Name        English     Math        Art         Gym         
Python18050003       Alice       0           0           0           0          
Please input the Grades!
<Python18050003>
English:89
Math::98
Gym:78
Art:88
the grades of student<Alice, Python18050003>update success!

Grades Of Students
1. Search all student grades
2. Search by student name
3. Search by student number
4. Return homepage
>>>1

Search Result:
Student_Number       Name        English     Math        Art         Gym         
Python18050001       Jefferson   99          98          99          97         
Python18050002       Tom         89          98          78          87         
Python18050003       Alice       89          98          78          88         
Python18050004       Lucy        0           0           0           0          
Python18050005       Tom         90          98          78          98         
Python18050007       Tom         0           0           0           0          
Python18050008       Jack        89          87          88          76         

1. Show average performance
2. Revise the grades of all the students
3. Revise one of the students' grades
4. Back
5. Return homepage
>>>2
Please input the Grades!
<Python18050001>
English:98
Math::67
Gym:45
Art:76
the grades of student<Jefferson, Python18050001>update success!

Search Result:
Student_Number       Name        English     Math        Art         Gym         Average_Grades
Python18050001       Jefferson   98          67          45          76          71.5
student<Python18050001 Jefferson> update grades success!
1. Continue update next
2. Back
>>>1
Please input the Grades!
<Python18050002>
English:54
Math::76
Gym:88
Art:99
the grades of student<Tom, Python18050002>update success!

Search Result:
Student_Number       Name        English     Math        Art         Gym         Average_Grades
Python18050002       Tom         54          76          88          99          79.25
student<Python18050002 Tom> update grades success!
1. Continue update next
2. Back
>>>1
Please input the Grades!
<Python18050003>
English:98
Math::78
Gym:89
Art:7
the grades of student<Alice, Python18050003>update success!

Search Result:
Student_Number       Name        English     Math        Art         Gym         Average_Grades
Python18050003       Alice       98          78          89          7           68.0
student<Python18050003 Alice> update grades success!
1. Continue update next
2. Back
>>>2

1. Show average performance
2. Revise the grades of all the students
3. Revise one of the students' grades
4. Back
5. Return homepage
>>>1

Search Result:
Student_Number       Name        English     Math        Art         Gym         Average_Grades
Python18050001       Jefferson   98          67          45          76          71.5
Python18050002       Tom         54          76          88          99          79.25
Python18050003       Alice       98          78          89          7           68.0
Python18050004       Lucy        0           0           0           0           0.0
Python18050005       Tom         90          98          78          98          91.0
Python18050007       Tom         0           0           0           0           0.0
Python18050008       Jack        89          87          88          76          85.0

 Class               Students    Average     Average     Average     Average     Average
Python1805           7           61.29       58.00       55.43       50.86       56.39

1. Show average performance
2. Revise the grades of all the students
3. Revise one of the students' grades
4. Back
5. Return homepage
>>>4

Grades Of Students
1. Search all student grades
2. Search by student name
3. Search by student number
4. Return homepage
>>>2
Please input the name of the student:Tom

Search Result:
Student_Number       Name        English     Math        Art         Gym         Average_Grades
Python18050002       Tom         54          76          88          99          79.25
Python18050005       Tom         90          98          78          98          91.0
Python18050007       Tom         0           0           0           0           0.0

1. Revise the students' grades
2. Back
3. Return homepage
>>>1
There are more than one student named Tom!
please input student number to revise:Python18050007
Please input the Grades!
<Python18050007>
English:89
Math::98
Gym:78
Art:99
the grades of student<Tom, Python18050007>update success!

Grades Of Students
1. Search all student grades
2. Search by student name
3. Search by student number
4. Return homepage
>>>1

Search Result:
Student_Number       Name        English     Math        Art         Gym         
Python18050001       Jefferson   98          67          45          76         
Python18050002       Tom         54          76          88          99         
Python18050003       Alice       98          78          89          7          
Python18050004       Lucy        0           0           0           0          
Python18050005       Tom         90          98          78          98         
Python18050007       Tom         89          98          78          99         
Python18050008       Jack        89          87          88          76         

1. Show average performance
2. Revise the grades of all the students
3. Revise one of the students' grades
4. Back
5. Return homepage
>>>5
********    Student Management  ********
**          1. Add Student            **
**          2. Search Student         **
**          3. Alter Student          **
**          4. Grades Of Students     **
**          5. Delete Student         **
**          6. Quit                   **
****************************************
Please input operation number:5
1. Delete by student number
2. Delete by name
3. Deldte all
4. Return homepage
>>>7
please input a legal order!
1. Delete by student number
2. Delete by name
3. Deldte all
4. Return homepage
>>>1
Please input the student number:Python180050004

Search Result:
Student_Number       Name        Sex     Age     Tel            
No information about the student was found!
The student number you input dose not exit!
1. Delete by student number
2. Delete by name
3. Deldte all
4. Return homepage
>>>1
Please input the student number:Python18050004

Search Result:
Student_Number       Name        Sex     Age     Tel            
Python18050004       Lucy        female  20      132455343      
1. Confirm Delete
2. Back
>>>1
delete<Python18050004> success!
1. Delete by student number
2. Delete by name
3. Deldte all
4. Return homepage
>>>2
Please input the name of the student:Tom

Search Result:
Student_Number       Name        Sex     Age     Tel            
Python18050002       Tom         male    20      17608175671    
Python18050005       Tom         male    21      6456543453     
Python18050007       Tom         male    23      4562455        

1. Delete all student that named Tom
2. Delete by student number
3. Back
>>>2
Please input the student number:Python18050007

Search Result:
Student_Number       Name        Sex     Age     Tel            
Python18050007       Tom         male    23      4562455        
1. Confirm Delete
2. Back
>>>1
delete<Python18050007> success!

1. Delete all student that named Tom
2. Delete by student number
3. Back
>>>3
1. Delete by student number
2. Delete by name
3. Deldte all
4. Return homepage
>>>2
Please input the name of the student:Tom

Search Result:
Student_Number       Name        Sex     Age     Tel            
Python18050002       Tom         male    20      17608175671    
Python18050005       Tom         male    21      6456543453     

1. Delete all student that named Tom
2. Delete by student number
3. Back
>>>1
All the student named Tom has been deleted!
1. Delete by student number
2. Delete by name
3. Deldte all
4. Return homepage
>>>3

Search Result:
student_number       Name        Sex     Age     Tel            
Python18050001       Jefferson   male    21      13096096557    
Python18050003       Alice       female  21      3161530        
Python18050008       Jack        male    21      43124234       
1. Confirm Delete
2. Back
>>>2
1. Delete by student number
2. Delete by name
3. Deldte all
4. Return homepage
>>>4
********    Student Management  ********
**          1. Add Student            **
**          2. Search Student         **
**          3. Alter Student          **
**          4. Grades Of Students     **
**          5. Delete Student         **
**          6. Quit                   **
****************************************
Please input operation number:6

Process finished with exit code 0

数据文件StudentInfomation.py

{
  "stuid": 8,
  "1": {
    "password": "1",
    "Python18050001": {
      "name": "Jefferson",
      "sex": "male",
      "age": "21",
      "tel": "13096096557",
      "grades": {
        "English": "98",
        "Gym": "76",
        "Art": "45",
        "Math": "67"
      }
    },
    "Python18050003": {
      "name": "Alice",
      "sex": "female",
      "age": "21",
      "tel": "3161530",
      "grades": {
        "English": "98",
        "Gym": "7",
        "Art": "89",
        "Math": "78"
      }
    },
    "Python18050008": {
      "name": "Jack",
      "sex": "male",
      "age": "21",
      "tel": "43124234",
      "grades": {
        "English": "89",
        "Gym": "76",
        "Art": "88",
        "Math": "87"
      }
    }
  },
  "2": {
    "password": "2"
  }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容