2018-09-02学生管理系统

2018-09-02  本文已影响23人  Smilebest

主界面

def main_interface():
    return print("""
    *****欢迎进入千峰学生管理系统****
    *         1.添加学生          *
    *         2.删除学生          *
    *         3.修改信息          *
    *         4.查找信息          *
    *         5.退出系统          *
    ******************************
    """)

学生管理系统

# 1.添加学生
def add_student():
    Students_table = []
    while True:
        with open('./student.txt', 'r', encoding='utf-8') as f:
            content = f.read()
            # print(eval(content))
        # f = open('./student.txt', 'r', encoding='utf-8')
        # f.read(str(student) + '\n')
        # f.close()
        name1 = input('请输入学生姓名:')
        age1  = input('请输入学生年龄:')
        tel1 = input('请输入学生电话:')
        student = {'name':name1,'age':age1,'tel': tel1}
        Students_table.append(student)
        with open('./student.txt', 'w', encoding='utf-8') as f:
            content = f.write(str(Students_table))
        # f = open('./student.txt', 'a', encoding='utf-8')
        # f.write(str(student) + '\n')
        # f.close()
        print('添加成功')
        print('==============================')
        print('1.继续添加')
        print('2.返回上一级')
        print('==============================')
        number2 =int (input('请选择:'))
        if number2 == 1:
            continue
        else:
            main_interface()
            option_number = int(input('请选择:'))
            if option_number == 1:
                add_student()
            elif option_number == 2:
                del_student()
            elif option_number == 3:
                recompose_student()
            elif option_number == 4:
                find_student()
            else:
                print('欢迎下次使用')
                break


# 2.删除学生
def del_student():
    while True:
        with open('./student.txt', 'r', encoding='utf-8') as f:
            Students_table = eval(f.read())
        print(Students_table)
        name2 = input('请输入需要删除学生的姓名:')
        for student in Students_table:
            if student['name'] == name2:
                Students_table.remove(student)
                print(Students_table)
                print('==============================')
                with open('./student.txt', 'w', encoding='utf-8') as f:
                    content = f.write(str(Students_table))
                print('删除成功')
                print('==============================')
                print('1.继续删除')
                print('2.退出')
                print('==============================')
                number2 = int(input('请选择:'))
                if number2 == 1:
                    print('==============================')
                    continue
                else:
                    main_interface()
                    option_number = int(input('请选择:'))
                    if option_number == 1:
                        add_student()
                    elif option_number == 2:
                        del_student()
                    elif option_number == 3:
                        recompose_student()
                    elif option_number == 4:
                        find_student()
                    else:
                        print('欢迎下次使用')
                        break

# 3.修改信息
def recompose_student():
    while True:
        with open('./student.txt', 'r', encoding='utf-8') as f:
            Students_table = eval(f.read())   # 从文件中取出的数据赋值个一个列表
            print(Students_table)
            name_gai = input('请输入要修改的姓名:')
            for student in Students_table:
                if student['name'] == name_gai:
                    print('=============================')
                    print(student)
                    print('==============================')
                    print('1.修改姓名')
                    print('2.修改年龄')
                    print('3.修改电话')
                    print('==============================')
                    number3 = int(input('请选择:'))
                    print('==============================')
                    if number3 == 1:
                        name3 = input('请输入修改后的姓名:')
                        print('============================')
                        student['name'] = name3
                    elif number3 == 2:
                        age3 = input('请输入修改后的年龄:')
                        print('============================')
                        student['age'] = age3
                    else:
                        tel3 = input('请输入修改后的电话:')
                        print('============================')
                        student['tel'] = tel3
                    print(Students_table)
                    with open('./student.txt', 'w', encoding='utf-8') as f:
                        content = f.write(str(Students_table))
                    print('==============================')
                    print('修改成功')
                    print('==============================')
            print('1.继续修改')
            print('2.退出')
            print('==============================')
            number3 = int(input('请选择:'))
            if number3 == 1:
                continue
            else:
                main_interface()
                option_number = int(input('请选择:'))
                if option_number == 1:
                    add_student()
                elif option_number == 2:
                    del_student()
                elif option_number == 3:
                    recompose_student()
                elif option_number == 4:
                    find_student()
                else:
                    print('欢迎下次使用')
                    break
# 4.查找信息
def find_student():
    while True:
        with open('./student.txt', 'r', encoding='utf-8') as f:
            Students_table = eval(f.read())  # 从文件中取出的数据赋值个一个列表
        print('1.按姓名查找')
        print('2.按年龄查找')
        print('3.按电话查找')
        print('==============================')
        number4 = int(input('请选择:'))
        print('==============================')
        if number4 == 1:
            name4 = input('请输入查找的学生姓名:')
            print('==============================')
            for student in Students_table:
                if student['name'] == name4:
                    print(student)
                    print('==============================')
            print('1.继续查找')
            print('2.退出')
            print('==============================')
            number4 = int(input('请选择:'))
            if number4 == 1:
                continue
            else:
                main_interface()
                option_number = int(input('请选择:'))
                if option_number == 1:
                    add_student()
                elif option_number == 2:
                    del_student()
                elif option_number == 3:
                    recompose_student()
                elif option_number == 4:
                    find_student()
                else:
                    print('欢迎下次使用')
                    break
        elif number4 == 2:
            age4 = input('请输入查找学生的年龄:')
            print('==============================')
            for student in Students_table:
                if student['age'] == age4:
                    print(student)
                    print('==============================')
            print('1.继续查找')
            print('2.退出')
            print('==============================')
            number4 = int(input('请选择:'))
            if number4 == 1:
                continue
            else:
                main_interface()
                option_number = int(input('请选择:'))
                if option_number == 1:
                    add_student()
                elif option_number == 2:
                    del_student()
                elif option_number == 3:
                    recompose_student()
                elif option_number == 4:
                    find_student()
                else:
                    print('欢迎下次使用')
                    break
        else:
            tel4 = input('请输入查找学生的电话:')
            print('==============================')
            for student in Students_table:
                if student['tel'] == tel4:
                    print(student)
                    print('==============================')
            print('1.继续查找')
            print('2.退出')
            print('==============================')
            number4 = int(input('请选择:'))
            if number4 == 1:
                continue
            else:
                main_interface()
                option_number = int(input('请选择:'))
                if option_number == 1:
                    add_student()
                elif option_number == 2:
                    del_student()
                elif option_number == 3:
                    recompose_student()
                elif option_number == 4:
                    find_student()
                else:
                    print('欢迎下次使用')
                    break

运行系统

main_interface()
option_number = int(input('请选择:'))
if option_number == 1:
    add_student()
elif option_number == 2:
    del_student()
elif option_number == 3:
    recompose_student()
elif option_number == 4:
    find_student()
else:
    print('欢迎下次使用')
上一篇下一篇

猜你喜欢

热点阅读