学生系统登录管理

system.py

"""__author__zhangdong__"""
import json
person = []
while True:
    print('===========================================')
    print('=            欢迎来到千锋管理系统          =')
    print('=              1. 登录                    =')
    print('=              2. 注册                    =')
    print('=              3. 离开                    =')
    print('===========================================')
    value = input('请选择(1,2,3):')
    if value == '1':
        while True:
            #开始登录
            user_name =input('请输入用户名:')
            user_number = input('请输入登录密码:')
            #在本地文件中找寻登录信息并且进行异常处理
            address = './'+'new_name'+'.json'
            try:
                with open(address,'r',encoding='utf-8') as ff:
                    content = ff.read()

            except FileNotFoundError:
                print('用户信息不存在')
                print('1.返回一层')
                print('继续登录')
                value1 = input('>>>')
                if value1 == '1':
                    break
                else:
                    continue
            else:
                for key in content:
                    if key == user_name and content['key'] == user_number:
                        print('登录成功')
                        from studentsystem import manger
                    else:
                        print('用户名或密码错误')
                        break




    elif value == '2':
        while True:
            print('开始注册')
            user_name = input('请输入注册名:')
            user_number = input('请输入密码:')
            address = './' + 'user_name' + '.json'
            try:
                with open(address, 'r', encoding='utf-8') as f:
                    user_name = json.load(f)

            except FileNotFoundError:
                print('继续注册')
                user_name = input('请输入注册名:')
                new_number = input('请输入密码:')
                # 将用户信息存入一个字典
                user_message = {}
                user_message['new_name'] = user_name
                user_message['new_number'] = new_number

                address = './' + 'user_name' + '.json'
                with open(address, 'w', encoding='utf-8') as ff:
                    content = json.dump(user_message, ff)
                    print('注册成功')
                    break
            else:
                print('注册成功')
                break

    else:
        print('1.确认离开')
        print('2.继续登录或者注册')
        value2 = input('请选择(1,2):')
        if value2 == '1':
            break

studentsystem.py

def manger():
    class1 =[]
    while True:
        print('欢迎进入班级学生管理系统')
        print('1.添加学生')
        print('2.查找学生')
        print('3.删除学生')
        print('4.学生成绩')
        print('q.退出系统')

        value = input('>>>')
        if value == '1':

            while True:
                name = input('请输入学生姓名:')
                id = input('请输入学生学号:')
                age = input('请输入学生年龄:')
                english =input('请输入学生英语成绩:')
                art = input('请输入学生美术成绩:')
                PE = input('请输入学生体育成绩:')
                math = input('请输入学生数学成绩:')
                message = {}
                message2 = {}

                message['name'] = name
                message['id'] = id
                message['age'] = age
                message2['english'] = english
                message2['art'] = art
                message2['PE'] = PE
                message2['math'] = math
                message['scores'] = message2
                class1.append(message)


                print(class1)
                print('1.继续添加')
                print('2.返回上一层')
                value2 = int(input('>>>'))
                if value2 ==1:
                    continue
                else:
                    break

        elif value == '2':

            while True:
                print('1.查看所有的学生信息')
                print('2.根据学生名字查看信息')
                print('3.返回上一层')
                value3 = int(input('>>>'))
                if value3 == 1:
                    print(class1)
                elif value3 == 2:
                    name1 = input('请输入要查询名字:')
                    print(class1[0])
                else:
                    break

        elif value == '3':

            while True:

                student_name = input('请输入要删除的学生姓名:')

                for student in class1:

                    if student['name'] == student_name:
                        print(class1.index(student), student)  # 找出学生所在的下标和学生信息

                        break

                student_mark = input('请输入要删除的学生的标号:')

                del class1[int(student_mark)]  # 根据下标删除学生

                print('删除成功')

                print('1.继续删除')

                print('2.返回上一层')

                value4 = input('>>>')

                if  value4 == '1':

                    continue

                elif  value4 == '2':

                    break


        elif value == '4':
            while True:
                print('1.计算学生平均成绩')
                print('2.返回上一层')
                value5 = input('>>>')
                if value5 == '1':
                    item = input('请输入要查询学生名字:')
                    average = sum(class1['scores'].values())

                    # for item in class1:
                    #
                    #     sum = 0
                    #     for key in item['scores']:
                    #         for i in item['scores'][key]:
                    #             sum += 1

                    print('该学生平均成绩为:%s'%(average/4))
                else:
                    break

        else:
            print('确认离开小管吗?')
            print('1.残忍离去')
            print('2.对不起,我爱你')
            value6 = input('>>>')
            if value6 == '1':
                break
            else:
                continue


你可能感兴趣的:(学生系统登录管理)