选课系统V1.0

Posted zhangmingda

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了选课系统V1.0相关的知识,希望对你有一定的参考价值。

 

技术分享图片
tree .
.
├── bin
│   ├── __init__.py
│   └── start.py #启动文件
├── conf
│   ├── __init__.py
│   └── settings.py #全局配置文件
├── core#核心代码目录
│   ├── CourseClass.py#课程类
│   ├── GradeClass.py #班级类
│   ├── __init__.py
│   ├── main.py #主程序
│   ├── RWdb.py #数据读写功能类
│   ├── SchoolClass.py #学校类
│   ├── SchoolPeopleClass.py #人员父类
│   ├── StudentsClass.py #学生类
│   └── TeacherClass.py #教师类
├── db  #存放各种对象数据
│   ├── course.db
│   ├── grade.db
│   ├── __init__.py
│   ├── school.db
│   ├── students.db
│   └── teachers.db
├── __init__.py
└── test#测试目录
    ├── __init__.py
    └── test.py
目录结构
技术分享图片
#!/usr/bin/env python
# Author:Zhangmingdad
import os
BASER_DIR =  os.path.dirname(os.path.dirname(os.path.abspath(__file__) ))

‘‘‘数据库文件路径/文件名配置‘‘‘
DB_PATH = os.path.join(BASER_DIR,db)
SCHOOL_DB_FILE = os.path.join(DB_PATH,school.db)
COURSE_DB_FILE = os.path.join(DB_PATH,course.db)
TEACHERS_DB_FILE = os.path.join(DB_PATH,teachers.db)
STUDENTS_DB_FILE = os.path.join(DB_PATH,students.db)
GRADE_DB_FILE = os.path.join(DB_PATH,grade.db)

‘‘‘系统统一入口视图配置‘‘‘
login_sys = {
    1:manager_sys(),
    2:students_sys(),
    3:teachers_sys()
}
smg_login_sys = ‘‘‘
    【1】 学校管理系统
    【2】 学生注册缴费查询系统
    【3】 教师办公系统
‘‘‘
‘‘‘后台管理视图配置‘‘‘
manager_sys = {
    1:create_course(),
    2:create_teacher(),
    3:create_grade(),
    4:create_school(),
    5:review_school_info()
}
smg_manager_sys = ‘‘‘
    【1】 创建课程
    【2】 招聘老师
    【3】 创建班级
    【4】 创建学校
    【5】 查看学校详情
‘‘‘

students_sys = {
    1:student_sign_in(),
    2:stu_paytuition(),
    3:show_score(),
    4:show_stu_info()
}
smg_students_sys = ‘‘‘
    【1】 注册
    【2】 缴费
    【3】 成绩查询
    【4】 查看个人信息
‘‘‘

teachers_sys = {
    1:show_teach_grades(),
    2:show_grade_students(),
    3:modify_stu_score(),
    4:show_teacher_info()
}
smg_teachers_sys = ‘‘‘
    【1】 查看所教班级
    【2】 查看班级学员列表
    【3】 修改学生成绩
    【4】 查看教师个人信息
‘‘‘

Manager_user = root
Manager_passwd = root
settings.py
技术分享图片
#!/usr/bin/env python
# Author:Zhangmingda
import  os,pickle
from conf import settings

class RWdb(object):
    ‘‘‘数据读写大类‘‘‘
    @staticmethod
    def readschooldb():
        ‘‘‘通过pickle的load方法读取学校信息‘‘‘
        if os.path.exists(settings.SCHOOL_DB_FILE):
            with open(settings.SCHOOL_DB_FILE,rb) as school_f:
                school_info = pickle.load(school_f)
        else:
            school_info = {}
        return school_info
    @staticmethod
    def writeschooldb(school_info):
        ‘‘‘通过pickle的dump存入学校信息‘‘‘
        with open(settings.SCHOOL_DB_FILE,wb) as school_f:
            pickle.dump(school_info,school_f)
#################课程读写#################################
    @staticmethod
    def readcoursedb():
        ‘‘‘通过pickle的load方法读取课程信息‘‘‘
        if os.path.exists(settings.COURSE_DB_FILE):
            with open(settings.COURSE_DB_FILE,rb) as course_f:
                course_info = pickle.load(course_f)
        else:
            course_info = {}
        return course_info
    @staticmethod
    def writecoursedb(course_info):
        ‘‘‘通过pickle的dump存入学校信息‘‘‘
        with open(settings.COURSE_DB_FILE,wb) as course_f:
            pickle.dump(course_info,course_f)
#################班级数据读写#################################
    @staticmethod
    def readgradedb():
        ‘‘‘通过pickle的load方法读取课程信息‘‘‘
        if os.path.exists(settings.GRADE_DB_FILE):
            with open(settings.GRADE_DB_FILE,rb) as grade_f:
                grade_info = pickle.load(grade_f)
        else:
            grade_info = {}
        return grade_info
    @staticmethod
    def writegradedb(grade_info):
        ‘‘‘通过pickle的dump存入学校信息‘‘‘
        with open(settings.GRADE_DB_FILE,wb) as grade_f:
            pickle.dump(grade_info,grade_f)
#################教师数据读写#################################
    @staticmethod
    def readteachersdb():
        ‘‘‘通过pickle的load方法读取课程信息‘‘‘
        if os.path.exists(settings.TEACHERS_DB_FILE):
            with open(settings.TEACHERS_DB_FILE,rb) as teachers_f:
                teachers_info = pickle.load(teachers_f)
        else:
            teachers_info = {}
        return teachers_info
    @staticmethod
    def writeteachersdb(teachers_info):
        ‘‘‘通过pickle的dump存入学校信息‘‘‘
        with open(settings.TEACHERS_DB_FILE,wb) as teachers_f:
            pickle.dump(teachers_info,teachers_f)
#################学生数据读写#################################
    @staticmethod
    def readstudentsdb():
        ‘‘‘通过pickle的load方法读取课程信息‘‘‘
        if os.path.exists(settings.STUDENTS_DB_FILE):
            with open(settings.STUDENTS_DB_FILE,rb) as students_f:
                students_info = pickle.load(students_f)
        else:
            students_info = {}
        return students_info
    @staticmethod
    def writestudentsdb(students_info):
        ‘‘‘通过pickle的dump存入学校信息‘‘‘
        with open(settings.STUDENTS_DB_FILE,wb) as students_f:
            pickle.dump(students_info,students_f)
RWdb.py
技术分享图片
#!/usr/bin/env python
# Author:Zhangmingda
import os,sys
BASER_DIR =  os.path.dirname(os.path.abspath(__file__) )
sys.path.append(BASER_DIR)
from  .SchoolClass import School
from conf import settings
def create_school():
    ‘‘‘创建一个学校‘‘‘
    back_flag = False
    while not back_flag:
        school_dict = School.readschooldb()
        ‘‘‘查看已有学校名字‘‘‘
        if len(school_dict):
            print(当前已存在学校如下:)
            for school_name in school_dict:
                print(school_name)
        ‘‘‘新建学校名字‘‘‘
        new_school_name = input(请输入要创建的学校名称(b返回):).strip()
        if new_school_name in school_dict or new_school_name == ‘‘:
            print(33[31;1m您要创建的学校名称不合法或已存在!请重新输入33[0m)
        elif new_school_name == b:
            back_flag = True
        else:
            ‘‘‘创建学校‘‘‘
            School(new_school_name)
            print(33[32;1m创建学校:%s OK!33[0m%new_school_name)
            chose_func = input(继续创建输入yes|任意键退出:)
            if chose_func == yes:
                continue
            else:
                back_flag = True

def review_school_info():
    ‘‘‘查看学校信息‘‘‘
    def show_school_students(sch_obj):
        print(本校学生共计:%s人 % len(sch_obj.school_students))
        for student in sch_obj.school_students:
            print(student)
    def show_school_teachers(sch_obj):
        print(本校老师共计:%s人% len(sch_obj.school_teachers))
        for teacher in sch_obj.school_teachers:
            print(teacher)
    def show_school_grades(sch_obj):
        print(本校设置班级共计:%s个 % len(sch_obj.school_grades))
        for grade in sch_obj.school_grades:
            print(grade)
    while True:
        school_dict = School.readschooldb()
        ‘‘‘查看已有学校名字‘‘‘
        if len(school_dict):
            print(当前已存在学校如下:)
            for school_name in school_dict:
                print(school_name)
            school_name = input(请输入要查询学校名称:).strip()
            if school_name in school_dict:
                print(%s 校区 详情如下:.center(50,#)% school_name)
                sch_obj = school_dict[school_name]
                show_school_students(sch_obj)
                show_school_teachers(sch_obj)
                show_school_grades(sch_obj)
                print(%s 校区详情查询完毕.center(50, #)% school_name)
            else:
                print(33[31;1m输入的学校名称不存在,请重新输入33[0m)
                continue
            chose_continue = input("继续查询,输入y| 其它任意键退出")
            if chose_continue == y:
                continue
            else:
                break
        else:
            print(33[31;1m当前没有任何学校33[0m)
            break

def create_course():
    ‘‘‘创建课程‘‘‘
    while True:
        school_dict = School.readschooldb()
        ‘‘‘查看已有学校名字‘‘‘
        if len(school_dict):
            print(33[34;1m请选择在哪个校区开设课程:33[0m)
            for school_name in school_dict:
                print(school_name)
        ‘‘‘选择学校名字‘‘‘
        chose_school = input(33[34;1m请输入选择的学校名称|b退出:33[0m).strip()
        if chose_school == b:
            break
        if chose_school in school_dict:
            sch_obj = school_dict[chose_school]
            sch_obj.create_course() #学校实例的创建课程方法
            break
        else:
            print(33[31;1m您输入的学校名不存在,请重新输入33[0m)

def create_teacher():
    ‘‘‘创建老师‘‘‘
    while True:
        school_dict = School.readschooldb()
        ‘‘‘查看已有学校名字‘‘‘
        if len(school_dict):
            print(33[34;1m为哪个校区招聘老师:33[0m)
            for school_name in school_dict:
                print(school_name)
        ‘‘‘选择学校名字‘‘‘
        chose_school = input(33[34;1m请输入选择的学校名称|b退出:33[0m).strip()
        if chose_school == b:
            break
        if chose_school in school_dict:
            sch_obj = school_dict[chose_school]
            sch_obj.create_teacher() #通过学校实例的创建老师方法
            break
        else:
            print(33[31;1m您输入的学校名不存在,请重新输入33[0m)

def create_grade():
    while True:
        school_dict = School.readschooldb()
        ‘‘‘查看已有学校名字‘‘‘
        if len(school_dict):
            print(33[34;1m要在哪个校区增设班级:33[0m)
            for school_name in school_dict:
                print(school_name)
        ‘‘‘选择学校名字‘‘‘
        chose_school = input(33[34;1m请输入选择的学校名称|b退出:33[0m).strip()
        if chose_school == b:
            break
        if chose_school in school_dict:
            sch_obj = school_dict[chose_school]
            sch_obj.create_grade()
            break
        else:
            print(33[31;1m您输入的学校名不存在,请重新输入33[0m)

def manager_sys():
    ‘‘‘后台管理系统‘‘‘
    login_status = False
    while not login_status:
        manager_user = input(输入管理员用户名:).strip()
        manager_passwd = input(输入管理员密码:).strip()
        if manager_user == settings.Manager_user and manager_passwd == settings.Manager_passwd:
            login_status = True
        else:
            print(33[31;1m管理员用户名或密码错误33[0m)
            break
    else:
        while True:
            print(欢迎进入33[32;1m选课后台管理33[0m系统.center(50, #))
            print(settings.smg_manager_sys)
            chose_func = input(请输入要选择的功能序号|b退出:).strip()
            if chose_func == b:
                break
            if chose_func in settings.manager_sys:
                eval(settings.manager_sys[chose_func])
            else:
                print(33[31;1m您输入的功能序号不存在,请重新输入33[0m)

def students_sys():

    def student_sign_in():
        ‘‘‘学生注册系统‘‘‘
        while True:
            school_dict = School.readschooldb()
            ‘‘‘查看已有学校名字‘‘‘
            if len(school_dict):
                print(33[34;1m请选择在哪个校区注册:33[0m)
                for school_name in school_dict:
                    print(school_name)
            chose_school = input(33[34;1m请输入选择的学校名称|b退出:33[0m).strip()
            if chose_school == b:
                break
            if chose_school in school_dict:
                sch_obj = school_dict[chose_school]
                sch_obj.add_student() #通过学校实例添加学员
                break
            else:
                print(33[31;1m您输入的学校名不存在,请重新输入33[0m)

    def stu_auth(func):
        ‘‘‘学生登录认证装饰器‘‘‘
        def stu_login(*args):
            while True:
                stu_name = input(请输入学员姓名|b退出:).strip()
                if stu_name in School.readstudentsdb():
                    stu_obj = School.readstudentsdb()[stu_name]
                    while True:
                        stu_passwd = input(请输入密码|b退出:).strip()
                        if stu_passwd == stu_obj.passwd:
                            func(stu_obj)
                            break
                        elif stu_passwd == b:
                            print(33[31;1m退出登录33[0m)
                            break
                        else:
                            print(33[31;1m密码错误33[0m)
                    break
                elif stu_name == b:
                    print(33[31;1m退出登录33[0m)
                    break
                else:
                    print(33[31;1m学生姓名不存在,请重新输入...33[0m)
        return stu_login
    @stu_auth
    def stu_paytuition(stu_obj):
        ‘‘‘使用学生对象交学费‘‘‘
        stu_obj.paytuition()
    @stu_auth
    def show_score(stu_obj):
        ‘‘‘查看学生成绩‘‘‘
        stu_obj.show_score()
    @stu_auth
    def show_stu_info(stu_obj):
        ‘‘‘查看个人信息‘‘‘
        stu_obj.student_info()

    while True:
        print(欢迎进入33[32;1m欢迎进入学生自助缴费注册查询系统33[0m.center(50, #))
        print(settings.smg_students_sys)
        chose_func = input(请输入要选择的功能序号|b退出:).strip()
        if chose_func == b:
            break
        if chose_func in settings.students_sys:
            while True:
                eval(settings.students_sys[chose_func])
                chose_continue = input(继续?(yes继续|任意键退出)).strip()
                if chose_continue != yes:
                    break
        else:
            print(33[31;1m您输入的功能序号不存在,请重新输入33[0m)

def teachers_sys():
    ‘‘‘老师功能系统‘‘‘
    teacher_auth_status = False
    # teacher_obj = None

    def auth_teacher(func):
        ‘‘‘检查教师登录状态装饰器‘‘‘
        def teacher_login(*args):
            if teacher_auth_status:
                func()
        return teacher_login
    @auth_teacher
    def show_teach_grades():
        print(查看所教班级信息.center(40,#))
        teacher_obj.show_teach_grades()
    @auth_teacher
    def show_grade_students():
        print(查看学员列表选择班级.center(40,#))
        teacher_obj.show_grade_students()
    @auth_teacher
    def modify_stu_score():
        ‘‘‘修改学员成绩‘‘‘
        show_teach_grades(teacher_obj)
        print(修改学员成绩信息.center(40, #))
        chose_grade = input(33[31;1m请选择班级33[0m).strip()
        while chose_grade in teacher_obj.teach_grade:
            grade_obj = School.readgradedb()[chose_grade]
            print(当前班级(%s)学员如下: % chose_grade)
            for student in grade_obj.students:
                print(student)
            while True:
                chose_student_name = input(33[32;1m请选择学员|b退出33[0m).strip()
                if chose_student_name in grade_obj.students:
                    student_obj = grade_obj.students[chose_student_name]
                    score_name = input(33[32;1m请输入科目名称:33[0m).strip()
                    score = input(33[32;1m请输入科目成绩:33[0m).strip()
                    student_obj.score[score_name] = score
                    ‘‘‘存储学生数据‘‘‘
                    students_info = student_obj.readstudentsdb()
                    students_info[chose_student_name] = student_obj
                    student_obj.writestudentsdb(students_info)
                    print(33[32;1m成绩修改成功!33[0m)
                    ‘‘‘存储到班级数据中‘‘‘
                    grade_info = student_obj.readgradedb()
                    grade_info[student_obj.stu_grade].students[student_obj.name] = student_obj
                    student_obj.writegradedb(grade_info)
                    ‘‘‘存储到学校数据中‘‘‘
                    school_info = student_obj.readschooldb()
                    ‘‘‘更新学校班级数据(中的学生数据)‘‘‘
                    school_info[student_obj.stu_school].school_grades[student_obj.stu_grade].students[
                        student_obj.name] = student_obj
                    ‘‘‘更新学校对象中的学生数据‘‘‘
                    school_info[student_obj.stu_school].school_students[student_obj.name] = student_obj
                    student_obj.writeschooldb(school_info)
                    # break
                elif chose_student_name == b:
                    break
                else:
                    print(33[31;1m输入的学生姓名不存在,请重新输入33[0m)
            break
        else:
            print(33[31;1m您选择的班级不存在33[0m)
    @auth_teacher
    def show_teacher_info():
        teacher_obj.teacher_info()


    while True:
        ‘‘‘登录认证循环体,保证任何一步不进入死循环‘‘‘
        teacher_name = input(请输入老师姓名|b退出:).strip()
        teachers_info = School.readteachersdb()
        if teacher_name in teachers_info:
            teacher_obj = teachers_info[teacher_name]
            while True:
                teacher_passwd = input(请输入密码|b退出:).strip()
                if teacher_passwd == teacher_obj.passwd:
                    teacher_auth_status = True
                    break
                elif teacher_passwd == b:
                    print(33[31;1m退出登录33[0m)
                    break
                else:
                    print(33[31;1m密码错误,请重新输入...33[0m)
            break
        elif teacher_name == b:
            print(33[31;1m退出登录33[0m)
            break
        else:
            print(33[31;1m教师姓名不存在,请重新输入...33[0m)

    while teacher_auth_status:
        print(欢迎进入33[32;1m欢迎进入教师管理系统33[0m.center(50, #))
        print(settings.smg_teachers_sys)
        chose_func = input(请输入要选择的功能序号|b退出:).strip()
        if chose_func == b:
            break
        if chose_func in settings.teachers_sys:
            while True:
                eval(settings.teachers_sys[chose_func])
                chose_continue = input(继续?(yes继续|任意键退出当前功能模块)).strip()
                if chose_continue != yes:
                    break
        else:
            print(33[31;1m您输入的功能序号不存在,请重新输入33[0m)

def login_sys():
    ‘‘‘登录总入口‘‘‘
    while True:
        print(欢迎进入老男孩33[32;1m学校选课系统33[0m.center(50, #))
        print(settings.smg_login_sys)
        chose_sub_sys = input(请输入要进入的子系统序号|b退出:).strip()
        if chose_sub_sys == b:
            break
        if chose_sub_sys in settings.login_sys:
            eval(settings.login_sys[chose_sub_sys])
        else:
            print(33[31;1m您输入的系统序号不存在,请重新输入33[0m)
main.py
技术分享图片
#!/usr/bin/env python
# Author:Zhangmingda
from SchoolPeopleClass import People
from RWdb import RWdb

class Student(People,RWdb):
    ‘‘‘定义学生角色应有的属性和方法‘‘‘
    def __init__(self,name,passwd,age,sex,stu_grade,school):
        super(Student,self).__init__(name,passwd,age,sex)
        self.stu_grade = stu_grade
        self.tuition = self.readcoursedb()[self.readgradedb()[stu_grade].course_name].price
        self.payment_status = 未缴
        self.stu_school = school
        self.score = {}
        ‘‘‘存储学生数据‘‘‘
        students_info = self.readstudentsdb()
        students_info[self.name] = self
        self.writestudentsdb(students_info)

    def paytuition(self):
        ‘‘‘学生交学费方法‘‘‘
        if self.payment_status == True:
            print(33[31;1m学费已交!无需再交33[0m)
        else:
            while True:
                print(您所在班级,所需缴费金额为:%s 元% self.tuition)
                pay_tuition = input(输入要缴费的金额:).strip()
                if pay_tuition.isnumeric()  and int(pay_tuition)  >= self.tuition:
                    self.payment_status = 已缴
                    ‘‘‘缴费后重新存储学生数据‘‘‘
                    students_info = self.readstudentsdb()
                    students_info[self.name] = self
                    self.writestudentsdb(students_info)
                    print(33[31;1m缴费成功!33[0m)
                    ‘‘‘存储到班级数据中‘‘‘
                    grade_info = self.readgradedb()
                    grade_info[self.stu_grade].students[self.name] = self
                    self.writegradedb(grade_info)

                    ‘‘‘存储到学校数据中‘‘‘
                    school_info = self.readschooldb()
                    ‘‘‘更新学校班级数据(中的学生数据)‘‘‘
                    school_info[self.stu_school].school_grades[self.stu_grade].students[self.name] = self
                    ‘‘‘更新学校对象中的学生数据‘‘‘
                    school_info[self.stu_school].school_students[self.name] = self
                    self.writeschooldb(school_info)
                    break

                elif pay_tuition == b:
                    print(33[32;1m您放弃了缴费33[0m)
                    break
                else:
                    print(33[32;1m金额不足|输入错误,请重缴!33[0m)

    def show_score(self):
        ‘‘‘查看学生成绩‘‘‘
        if len(self.score):
            print(33[33;1m学员:%s成绩如下33[0m.center(50,#)% self.name)
            for score_name in self.score:
                print(33[32;1m科目:%s	成绩:%s33[0m% (score_name,self.score[score_name]))
        else:
            print(33[31;1m当前没有任何成绩可以查询33[0m)

    def student_info(self):
        ‘‘‘查看学生个人信息‘‘‘
        stu_info = ‘‘‘
        姓名:%s
        年龄:%s
        性别:%s
        所在班级:%s
        所在学校:%s
        应缴学费:%s
        缴费状态:%s‘‘‘%(self.name,self.age,self.sex,self.stu_grade,self.stu_school,self.tuition,self.payment_status)
        print(33[33;1m:%s 你好,您的个人信息如下33[0m.center(50,#)% self.name)
        print(stu_info)
StudentsClass.py
技术分享图片
#!/usr/bin/env python
# Author:Zhangmingda

from RWdb import RWdb
from CourseClass import Course
from GradeClass import Grade
from TeacherClass import Teacher
from StudentsClass import Student

class School(RWdb):
    def __init__(self,name):
        self.school_name = name
        self.school_course = {}
        self.school_teachers = {}
        self.school_students = {}
        self.school_grades = {}
        school_info =  self.readschooldb()
        school_info[self.school_name] = self
        self.writeschooldb(school_info)

    def create_course(self):
        ‘‘‘管理员创建课程‘‘‘
        while True:
            if len(self.school_course):
                print(当前本校已开设课程:)
                for course_name in self.school_course:
                    print(course_name)
            new_course_name = input(请输入要创建的课程名称(b退回):).strip()
            if new_course_name in self.school_course or new_course_name == ‘‘:
                print(33[31;1m您要创建的课程已存在或不合法!请重新输入33[0m)
                continue
            elif new_course_name  == b:
                break
            else:
                while True :
                    price = input(输入课程价格:).strip()
                    if price.isnumeric():
                        price = int(price)
                        break
                    else:
                        print("33[31;1m课程价格必须为纯数字,请重新输入....33[0m")
                preiod = input(计划课程周期:).strip()
                new_course = Course(new_course_name,price,preiod)
                school_info = self.readschooldb()
                self.school_course[new_course_name] = new_course
                school_info[self.school_name] = self
                self.writeschooldb(school_info)
                print(33[32;1m创建课程:%s OK!33[0m % new_course_name)
                # break

    def create_teacher(self):
        ‘‘‘管理员创建老师‘‘‘
        while True:
            teachers_info = self.school_teachers
            ‘‘‘当前校区已存在老师名单:‘‘‘
            if len(teachers_info):
                print(当前学校已招聘老师名单:)
                for school_teacher in teachers_info:
                    print(school_teacher)
            new_teacher_name = input(输入要新招聘的老师名字(b退出):).strip()
            if new_teacher_name in teachers_info or new_teacher_name == ‘‘:
                print(33[31;1m该老师已经存在(或不合法),请重新输入~33[0m)
                continue
            elif new_teacher_name == b:
                break

            else:
                while True:
                    age = input(老师年方几何:)
                    if age.isdigit() and 0 < int(age) < 150:
                        break
                    else:
                        print(年龄必须为大于0,小于150的整数)
                sex = input(请输入性别:).strip()
                course = input(老师教什么:).strip()
                salary = input(要多少工资:).strip()
                passwd = input(请为您设置密码:).strip()
                new_teacher_obj = Teacher(new_teacher_name,passwd,age,sex,course,salary,self.school_name)
                self.school_teachers[new_teacher_name] = new_teacher_obj
                school_info = self.readschooldb()
                school_info[self.school_name] = self
                self.writeschooldb(school_info)
                print(老师:%s创建成功% new_teacher_name)

    def create_grade(self):
        ‘‘‘管理员创建班级‘‘‘
        while True:
            grade_info = self.school_grades
            if len(grade_info):
                print(当前已经开设的班级如下:)
                for grade_name in grade_info:
                    print(grade_name)
            if len(self.school_course) == 0:
                print(33[31;1m当前学校未开设任何课程,请先创建课程,再创建班级33[0m)
                break
            new_grade_name = input(请输入要创建的班级名称(b退回):).strip()
            if new_grade_name in self.school_grades or new_grade_name == ‘‘:
                print(33[31;1m您要创建的班级已存在(或不合法),Please 重新输入33[0m)
                continue
            elif new_grade_name == b:
                break
            # else:
            while True:
                print(当前本校已开设课程如下,请为班级选择课程:)
                for course_name in self.school_course:
                    print(course_name)
                chose_course = input(请选择>>>:).strip()
                if chose_course in self.school_course:
                    break
                else:
                    print(您输入的课程不存在,请重新输入:)
                # else:

            if len(self.school_teachers ) == 0:
                print(33[31;1m当前学校未招聘任何老师,请先再创建班级33[0m)
                break
            while True:
                print(本校区已招聘老师名单如下:)
                for teacher_name in self.school_teachers :
                    print(teacher_name)
                chose_teacher = input(请为班级选择老师>>>:).strip()
                if chose_teacher  in self.school_teachers:
                    break
                else:
                    print(33[31;1m您输入的老师不存在33[0m)

            grade_start_time = input(输入班级开课时间:).strip()
            new_grade = Grade(new_grade_name, chose_course, chose_teacher, grade_start_time)
            self.school_grades[new_grade_name] = new_grade
            ‘‘‘下面将新创建的班级添加到学校数据库中‘‘‘
            school_info = self.readschooldb()
            school_info[self.school_name] = self
            self.writeschooldb(school_info)
            print(33[32;1m建班级:%s成功!33[0m% new_grade_name)

    def add_student(self):
        ‘‘‘管理员自主添加学员‘‘‘
        while True:
            grade_info = self.school_grades
            if len(grade_info):
                print(添加学员,请先选择班级,当前本校区已经开设的班级如下:)
                for grade_name in grade_info:
                    print(grade_name)
                chose_grade = input(33[31;1m请输入要选择班级(b退出):33[0m).strip()
                if chose_grade in self.school_grades:
                    while True:
                        name = input(输入要添加的学员名字:).strip()
                        if name in self.school_grades[chose_grade].students or name == ‘‘:
                            print(33[31;1m学员名字不合法,或班级内已存在,请重新输入...33[0m)
                        else:
                            break
                    while True:
                        age = input(输入学员年龄:)
                        if age.isdigit() and 0 < int(age) < 150:
                            break
                        else:
                            print(年龄必须为大于0,小于150的整数)
                    sex = input(输入学员性别:).strip()
                    passwd = input(为学员设置密码:).strip()
                    ‘‘‘创建学员‘‘‘
                    stu_obj = Student(name,passwd,age,sex,chose_grade,self.school_name)
                    ‘‘‘存储到学校数据‘‘‘
                    self.school_grades[chose_grade].students[name] = stu_obj
                    self.school_students[name] = stu_obj
                    school_info = self.readschooldb()
                    school_info[self.school_name] = self
                    self.writeschooldb(school_info)
                    ‘‘‘存储到班级数据中‘‘‘
                    grade_info = self.readgradedb()
                    grade_info[chose_grade].students[name] = stu_obj
                    self.writegradedb(grade_info)
                    print(33[32;1m学员:%s注册成功!信息如下请牢记自己的密码33[0m% name)
                    stu_info = ‘‘‘
                    姓名:%s
                    年龄:%s
                    性别:%s
                    班级:%s
                    应缴学费:%s
                    缴费状态:%s
                    所属校区:%s
                    课程成绩:%s
                    ‘‘‘%(stu_obj.name,stu_obj.age,stu_obj.sex,stu_obj.stu_grade,stu_obj.tuition,stu_obj.payment_status,stu_obj.stu_school,stu_obj.score)
                    print(stu_info)
                    break
                elif chose_grade == b:
                    break
                else:
                    print(33[31;1m您选择的班级不存在33[0m)
            else:
                print(33[31;1m当前学校未设置任何班级,请先添加班级后再添加学员33[0m)
                break
SchoolClass.py
技术分享图片
#!/usr/bin/env python
# Author:Zhangmingda
from RWdb import RWdb

class Course(RWdb):
    ‘‘‘定义一个课程有哪些属性&方法‘‘‘
    def __init__(self,course_name,price,period):
        self.course_naem = course_name
        self.price = price
        self.period = period
        ‘‘‘获取所有校区最新课程数据‘‘‘
        course_info = self.readcoursedb()
        ‘‘‘添加刚刚创建的课程对象,到获取 最新课程数据中‘‘‘
        course_info[self.course_naem] = self
        ‘‘‘将更新后的数据保存到文件中‘‘‘
        self.writecoursedb(course_info)
CourseClass.py
技术分享图片
#!/usr/bin/env python
# Author:Zhangmingda
from RWdb import RWdb
class Grade(RWdb):
    ‘‘‘定义一个班级的样子(属性:名字课程老师学生)‘‘‘
    def __init__(self,name,course,teacher,start_time):
        self.grade_name = name
        self.course_name = course
        self.teachers_name = []
        self.teachers_name.append(teacher)
        self.start_time = start_time
        self.students = {}
        ‘‘‘将新创建的实例加入到已有实例字典中‘‘‘
        grade_info = self.readgradedb()
        grade_info[self.grade_name] = self
        self.writegradedb(grade_info)

        teachers_info = self.readteachersdb()
        teachers_info[teacher].teach_grade[self.grade_name] = self
        self. writeteachersdb(teachers_info)
GradeClass.py
技术分享图片
#!/usr/bin/env python
# Author:Zhangmingda
from RWdb import RWdb
from SchoolPeopleClass import People
class Teacher(People,RWdb):
    ‘‘‘定义一个老师该有的属性和方法‘‘‘
    def __init__(self,name,passwd,age,sex,course,salary,school):
        super(Teacher,self).__init__(name,passwd,age,sex)
        self.teacher_course = course
        self.teacher_salary = salary
        self.teacher_school = school
        self.teach_grade = {}
        ‘‘‘定义后就存储起来老师数据‘‘‘
        teachers_info = self.readteachersdb()
        teachers_info[self.name] = self
        self. writeteachersdb(teachers_info)
    def show_teach_grades(self):
        print(33[32;1m您所教班级如下:33[0m)
        for grade in self.teach_grade:
            print(grade)
    def show_grade_students(self):
        while True:
            self.show_teach_grades()
            # print(‘查看所教班级学员列表‘.center(40, ‘#‘))
            chose_grade = input(33[31;1m请输入要查看的班级名称33[0m).strip()
            if chose_grade in self.teach_grade:
                grade_obj = self.readgradedb()[chose_grade]
                print(当前班级(%s)学员如下:% chose_grade)
                for student in grade_obj.students:
                    print(student)
                break
            else:
                print(33[31;1m您选择的班级不存在,请重新输入33[0m)

    def teacher_info(self):
        ‘‘‘查看教师个人信息‘‘‘
        teacher_info = ‘‘‘
        姓名:%s
        年龄:%s
        性别:%s
        所教班级:%s
        所教课程:%s
        所在学校:%s
        当前工资:%s‘‘‘%(self.name,self.age,self.sex,self.teach_grade.keys(),self.teacher_course,self.teacher_school,self.teacher_salary)
        print(33[33;1m:%s 你好,您的个人信息如下33[0m.center(50,#)% self.name)
        print(teacher_info)
TeacherClass.py
技术分享图片
#!/usr/bin/env python
# Author:Zhangmingda
class People(object):
    def __init__(self,name,passwd,age,sex):
        self.name = name
        self.passwd = passwd
        self.age = age
        self.sex = sex
SchoolPeopleClass.py
技术分享图片
#!/usr/bin/env python
# Author:Zhangmingda
import os,sys
BASER_DIR =  os.path.dirname(os.path.dirname(os.path.abspath(__file__) ))
sys.path.append(BASER_DIR)
from core import main

if __name__ == __main__:
    main.login_sys()
start.py

 

以上是关于选课系统V1.0的主要内容,如果未能解决你的问题,请参考以下文章

java学生选课系统

JAVA | 学生选课系统

自制简单选课系统模拟代码

XK关系型学生选课数据库,关系如下:

面向对象的应用:学生选课系统

数据库实验(学生选课系统)