美文网首页
学生管理系统2.0 函数版

学生管理系统2.0 函数版

作者: _最美不是下雨天_ | 来源:发表于2019-01-08 09:12 被阅读0次
    import function
    all_students =[]
    while True:
        if function.log():
            while True:
               function.interface1()
               contrl1 = input('请选择(1-5):')
               if contrl1=='1':
                   function.wg_input(all_students)
               elif contrl1 == '2':
                   while True:
                    print('1.❤查看所有学生')
                    print('2.❤按姓名查找')
                    print('3.❤按学号查找')
                    print('4.❤返回')
                    sel = input('请选择(1-4):')
                    function.wg_sel(all_students,sel)
                    if sel =='4':
                        break
               elif contrl1 == '3':
                   while True:
                     print('1.❤按姓名查找修改')
                     print('2.❤按学号查找修改')
                     print('3.❤返回')
                     upda = input('请选择:(1-3):')
                     function.wg_update(all_students,upda)
                     if upda =='3':
                         break
               elif contrl1 == '4':
                   while True:
                       print('1.❤按学号查找删除')
                       print('2.❤按姓名查找')
                       print('3.❤返回')
                       del1 = input('请选择(1-3):')
                       function.wg_del(all_students,del1)
                       if del1 =='3':
                            break
               elif contrl1 == '5':
                   break
               else:
                   print('输入错误,请重新输入:')
                   continue
        else:print('密码错误,请重新输入:')
        continue
    

    function:

    def log():
        print('================================')
        username = input('请输入用户名:')
        password = input('请输入密码:')
        print('================================')
        if username =='wangguo' and password=='123456':
            return True
    
    def interface1():
        print('================================')
        print('❀❀欢迎您:wangguo' )
        print('1.❤添加学生')
        print('2.❤查看学生')
        print('3.❤修改学生信息')
        print('4.❤删除学生')
        print('5.❤返回')
        print('================================')
    def wg_input(all_students:list):
        def get_num():
            num = 1
            while True:
                yield  '1%03.d' % (num)
                num += 1
        num_gen = get_num()
        while True:
                addname = input('请输入姓名:')
                addage = int(input('请输入年龄:'))
                addscore = int(input('请输入成绩:'))
                addtel = input('请输入电话:')
                all_students.append(
                {'name': addname, 'num': next(num_gen), 'age': addage, 'score': addscore, 'tel': addtel})
                print('添加成功')
                print('1.❤继续添加')
                print('2.❤退出')
                contrl2 = input('请选择(1-2):')
                if contrl2 == '1':
                    continue
                else:
                    break
    def wg_sel(all_students:list,sel):
            if sel == '1':
                for item1 in all_students:
                    print(item1)
            elif sel == '2':
                name1 = input('请输入您要查询的姓名:')
                i = 0
                list1 = []
                while i in range(len(all_students)):
                    if all_students[i]['name'] == name1:
                        list1.append(all_students[i])
                    i += 1
                if len(list1) == 0:
                    print('没有找到该记录!!')
                else:
                    for n in list1:
                        print(n)
            elif sel == '3':
                list2 = []
                num = input('请输入您要查询的学号:')
                for i in all_students:
                    if num == i['num']:
                        list2.append(i)
                if len(list2) == 0:
                    print('没有找到该记录!!')
                else:
                    for n in list2:
                        print(n)
    def wg_update(all_students:list,upda):
        if upda == '1':
            upname = input('请输入您需要修改的姓名:')
            for i in all_students:
                if i['name'] == upname:
                    print('1.❤修改姓名')
                    print('2.❤修改学号')
                    print('3.❤修改年龄')
                    print('4.❤修改成绩')
                    print('5.❤修改电话')
                    print('6.❤返回')
                    upname1 = input('请输入您需要修改的信息:')
                    if upname1 == '1':
                        upname2 = input('请输入修改后的姓名:')
                        i['name'] = upname2
                        print('修改成功')
                    elif upname1 == '2':
                        upnum2 = input('请输入修改后的学号:')
                        i['num'] = upnum2
                        print('修改成功')
                    elif upname1 == '3':
                        upage2 = input('请输入修改后的年龄:')
                        i['age'] = upage2
                        print('修改成功')
                    elif upname1 == '4':
                        upscore2 = input('请输入修改后的成绩:')
                        i['score'] = upscore2
                        print('修改成功')
                    elif upname1 == '5':
                        uptel2 = input('请输入修改后的电话:')
                        i['tel'] = uptel2
                        print('修改成功')
                    elif upname1 == '6':
                        break
        if upda == '2':
            upnum = input('请输入您需要修改的学号:')
            for i in all_students:
                if i['num'] == upnum:
                    print('1.❤修改姓名')
                    print('2.❤修改学号')
                    print('3.❤修改年龄')
                    print('4.❤修改电话')
                    print('5.❤修改成绩')
                    print('6.❤返回')
                    upname1 = input('请输入您需要修改的信息:')
                    if upname1 == '1':
                        upname2 = input('请输入修改后的姓名:')
                        i['name'] = upname2
                        print('修改成功')
                    elif upname1 == '2':
                        upnum2 = input('请输入修改后的学号:')
                        i['num'] = upnum2
                        print('修改成功')
                    elif upname1 == '3':
                        upage2 = input('请输入修改后的年龄:')
                        i['age'] = upage2
                        print('修改成功')
                    elif upname1 == '4':
                        upscore2 = input('请输入修改后的成绩:')
                        i['score'] = upscore2
                        print('修改成功')
                    elif upname1 == '5':
                        uptel2 = input('请输入修改后的电话:')
                        i['tel'] = uptel2
                        print('修改成功')
                    elif upname1 == '6':
                        break
    def wg_del(all_students:list,del1):
        if del1 == '1':
            del2 = input('请输入您需要删除的学号:')
            list2 = []
            for i in all_students[:]:
                if del2 == i['num']:
                    list2.append(i)
            if len(list2) == 0:
                print('没有找到该记录!!')
            else:
                print('确定删除吗?')
                print('1.确定')
                print('2.返回')
                sure = input('请选择:')
                if sure == '1':
                    for i in all_students[:]:
                        if del2 == i['num']:
                            all_students.remove(i)
                            print('删除成功!')
                            print(all_students)
                        else:
                            break
        if del1 == '2':
            name1 = input('请输入您要查询的姓名:')
            i = 0
            list1 = []
            while i in range(len(all_students)):
                if all_students[i]['name'] == name1:
                    list1.append(all_students[i])
                i += 1
            if len(list1) == 0:
                print('没有找到该记录!!')
            else:
                for n in range(len(list1)):
                    print(n,list1[n])
                sure = int(input('请选择你所需要删除的序号:'))
                all_students.remove(list1[sure])
                print('删除成功!')
    

    相关文章

      网友评论

          本文标题:学生管理系统2.0 函数版

          本文链接:https://www.haomeiwen.com/subject/tczmrqtx.html