day 10 homework

"""__author__  夏伟鑫"""
list_stu = []


def st_mi():
    while 1:
        print('=========Welcome to Student Management System===========')
        print('                    1.显示学生信息')
        print('                    2.查询学生信息')
        print('                    3.添加学生信息')
        print('                    4.修改学生信息')
        print('                    5.删除学生信息')
        print('                             输入-1   退出系统')
        x = in_num_01()
        # 输入操作序号函数
        if x == 1:
            show_all()
        elif x == 2:
            find_stu()
        elif x == 3:
            add_stu()
        elif x == 4:
            pass
        elif x == 5:
            pass


def in_num_01():
    # 输入操作序号函数
    return int(input('请输入操作的序号'))


def show_all():
    # 展示所有学生信息
    for x in list_stu:
        print(x)

    pass


def find_stu():
    # 查询学生信息
    print('1.按照姓名查找')
    print('2.按照学号查找')
    print('3.返回上一层')
    find_num = in_num_01()
    if find_num == 1:
        stu_name = input('请输入学生姓名')
        temp = 0
        for x in range(len(list_stu)):
            if list_stu[x]['name'] == stu_name:
                print('stu_name:'+list_stu[x]['name']+' '+'stu_num:'+list_stu[x]['num']+' '+'stu_age:'+list_stu[x]['age'])
                temp += 1
        if temp == 0:
            print('没有找到该学生')
        print('1.继续查找')
        print('2.返回')
        x1 = in_num_01()
        if x1 == 1:
            find_stu()
        elif x1 == 2:
            st_mi()
        else:
            print('请输入1-2的数字')
        pass
    elif find_num == 2:
        stu_num = input('请输入学生学号')
        temp = 0
        for x in range(len(list_stu)):
            if list_stu[x]['num'] == stu_num:
                print('stu_name:'+list_stu[x]['name']+' '+'stu_num:'+list_stu[x]['num']+' '+'stu_age:'+list_stu[x]['age'])
                temp += 1
        if temp == 0:
            print('没有找到该学生')
        print('1.继续查找')
        print('2.返回')
        x1 = in_num_01()
        if x1 == 1:
            find_stu()
        elif x1 == 2:
            st_mi()
        else:
            print('请输入1-2的数字')
        pass

    elif find_num == 3:
        st_mi()
    else:
        print('请输入1-3的数字')


def add_stu():
    # 增加学生信息
    stu_name = input('请输入学生姓名')
    stu_num = input('请输入学生学号')
    stu_age = input('请输入学生年龄')
    student = {'name': stu_name, 'age': stu_age, 'num': stu_num}
    list_stu.append(student)

    print('1.继续输入')
    print('2.返回')
    x1 = in_num_01()
    if x1 == 1:
        add_stu()
    elif x1 == 2:
        st_mi()
    else:
        print('请输入1-2的数字')


def del_stu():
    # 删除学生信息
    print('1.按照姓名删除')
    print('2.按照学号删除')
    print('3.返回上一层')
    del_num = in_num_01()
    temp = 0
    if del_num == 1:
        del_name = input('请输入姓名')
        for x in list_stu:
            if x['name'] == del_name:
                del x
                temp = 1
        if temp == 0:
            print('未找到该学生')
    elif del_num == 2:
        del_num1 = input('请输入学号')
        for x in list_stu:
            if x['num'] == del_num1:
                del x
                temp = 1
        if temp == 0:
            print('未找到该学生')
    elif del_num == 3:
        st_mi()
    else:
        print('请输入1-3的数字')


def rewrite_str():
    # 修改学生信息
    print('1.修改姓名')
    print('2.修改学号')
    print('3.修改年龄')
    rs = in_num_01()
    temp = 0

    if rs == 1:
        rs_name = input('请输入姓名')
        for x in list_stu:
            if x['name'] == rs_name:
                x['name'] = input('输入修改的名字')
                temp = 1
        if temp == 0:
            print('未找到该学生')
    if rs == 2:
        rs_num = input('请输入学号')
        for x in list_stu:
            if x['num'] == rs_num:
                x['num'] = input('输入修改的学号')
                temp = 1
        if temp == 0:
            print('未找到该学生')
    pass


st_mi()

你可能感兴趣的:(day 10 homework)