2019-01-03作业学生管理系统

str1 = '''
# ====================================
# 欢迎yuting:
# 
#      1.  添加学生
#      2.  查看学生
#      3.  修改学生信息
#      4.  删除学生
#      5.  返回
# ======================================
'''


def func1():
    num8 = 1
    while True:
        yield num8
        num8 += 1


a = func1()
list1 = []
while True:
    print(str1)
    num1 = int(input('请选择(1-5):'))
    if num1 == 1:
        while True:
            dict1 = {'学号': 'xx', '姓名': 'yy', '年龄': 'zz', '电话': 'aa'}
            str2 = str(next(a))
            xuehao = 'stu' + str2.rjust(3, '0')
            dict1['学号'] = xuehao
            name = input('请输入学生姓名:')
            for index in list1:
                if index['姓名'] == name:
                    print('不好意思!名字重复请加个区分标志!')
                else:
                    dict1['姓名'] = name
            age = input('请输入学生的年龄:')
            dict1['年龄'] = age
            tel = input('请输入学生的电话:')
            dict1['电话'] = tel
            list1.append(dict1)
            print('添加成功!\n1.继续\n2.返回')
            num2 = int(input('请选择(1-2):'))
            if num2 != 1:
                break
    elif num1 == 2:
        while True:
            num3 = int(input('1.查看所有学生\n2.按姓名查找\n3.按学号查找\n4.返回\n请输入(1-4):'))
            if num3 == 1:
                for index in list1:
                    print(index)
            elif num3 == 2:
                name1 = input('请输入您要查找的学生姓名:')
                count2 = 0
                for index in list1:
                    if index['姓名'] == name1:
                        count2 += 1
                        print(index)
                        if count2 == 0:
                            print('无此学生信息!')
            elif num3 == 3:
                num3 = input('请输入您要查找的学生学号:')
                count3 = 0
                for index in list1:
                    if index['学号'] == num3:
                        count3 += 1
                        print(index)
                        if count3 == 0:
                            print('无此学生信息!')
            elif num3 == 4:
                break
    elif num1 == 3:
        while True:
            num5 = int(input('1.按学生姓名修改\n2.按学生学号修改\n3.返回\n请输入(1-3)'))
            if num5 == 1:
                name2 = input('请输入您要修改学生信息的学生姓名:')
                for index in list1:
                    if index['姓名'] == name2:
                        index['姓名'] = input('请输入姓名:')
                        index['年龄'] = input('请输入年龄:')
                        index['电话'] = input('请输入电话:')
            elif num5 == 2:
                num6 = input('请输入您要修改学生信息的学生学号:')
                for index in list1:
                    if index['学号'] == num6:
                        index['姓名'] = input('请输入姓名:')
                        index['年龄'] = input('请输入年龄:')
                        index['电话'] = input('请输入电话:')
            elif num5 == 3:
                break
    elif num1 == 4:
        while True:
            num4 = int(input('1.按学生姓名删除\n2.按学生学号删除\n3.返回\n请输入(1-3)'))
            if num4 == 1:
                name2 = input('请输入您要删除学生信息的学生姓名:')
                for index in list1:
                    if index['姓名'] == name2:
                        list1.remove(index)
            elif num4 == 2:
                num7 = input('请输入您要删除学生信息的学生学号:')
                for index in list1:
                    if index['学号'] == num7:
                        list1.remove(index)
            elif num4 == 3:
                break
    elif num1 == 5:
        break        

你可能感兴趣的:(2019-01-03作业学生管理系统)