day15-16homework

1.学生管理系统

    def update_student(self):
        """修改学生信息"""
        while True:
            stu_id = input('请输入需要修改学生的学号:')
            for stu in self.all_students:
                if stu_id == stu.study_id:
                    print('学生当前信息为:\n', stu.__dict__)
                    for information in stu.__dict__:
                        # stu.information = input('请输入新的%s'%information)
                        infor = input('请输入新的%s,输入 q 跳过该项修改' % information)
                        if infor == 'q':
                            continue
                        setattr(stu, information, infor)
                    print('修改成功!!')
                    break
            else:
                print('没有这个学生!!!')
            print('1.继续\n2.返回')
            value = input('请选择(1-2):')
            if value != '1':
                break

    def show_page(self):
        """展示主页"""
        while True:
            page = """
    ====================================
        欢迎来到千锋学生管理系统
    
        ♥ 1.  添加学生
        ♥ 2.  查看学生
        ♥ 3.  修改学生信息
        ♥ 4.  删除学生
        ♥ 5.  退出
    ======================================
            """
            print(page)
            value = input('请选择(1-5):')
            if value == '1':
                # 添加学生
                self.add_student()
            elif value == '2':
                # 查看学生
                self.find_student()

            elif value == '3':
                # 修改学生信息
                self.update_student()
            elif value == '4':
                # 删除学生
                self.del_student()
            else:
                exit()

    def login_page(self):


        """展示登陆界面"""
        page = """
        ====================================
        欢迎来到千锋学生管理系统
    
        ♥ 1.  登陆
        ♥ 2.  注册
        ♥ 3.  退出

    ======================================
        
        """
        flag = True
        while flag:
            with open('./files/managers.json', 'r', encoding='utf-8') as f:
                managers = json.load(f)
            print(page)
            order = input('请选择1-3:')
            if order == '3':
                exit()

            elif order == '2':
                accont = input('请输入账号:')
                for manager in managers:
                    while manager['acc'] == accont:
                        accont = input('已存在账号,请重新输入。。')
                else:
                    print('可以使用账号~')

                password = input('请输入密码:')
                manager = {'acc': accont, 'pswd': password}
                managers.append(manager)
                with open('./files/managers.json', 'w', encoding='utf-8') as f:
                    json.dump(managers, f)
                print('注册成功!!!')

            if order == '1':
                accont = input('请输入账号:')
                for manager in managers:
                    if accont == manager['acc']:
                        password = input('请输入密码:')
                        if password == manager['pswd']:
                            print('登陆成功!!!!')
                            flag = False
                            break
                        else:
                            print('密码错误!!!')
                else:
                    print('账号不存在!!!')
        self.show_page()





你可能感兴趣的:(day15-16homework)