選課系統

選課系統:python

角色:學校、學員、課程、講師linux

要求:git

1. 建立北京、上海 2 所學校app

2. 建立linux , python , go 3個課程 , linux\py 在北京開, go 在上海開ide

3. 課程包含,週期,價格,經過學校建立課程測試

4. 經過學校建立班級, 班級關聯課程、講師ui

5. 建立學員時,選擇學校,關聯班級spa

5. 建立講師角色時要關聯學校,3d

6. 提供兩個角色接口code

6.1 學員視圖, 能夠註冊, 交學費, 選擇班級,

6.2 講師視圖, 講師可管理本身的班級, 上課時選擇班級, 查看班級學員列表 , 修改所管理的學員的成績

6.3 管理視圖,建立講師, 建立班級,建立課程

7. 上面的操做產生的數據都經過pickle序列化保存到文件裏

 

readme:

功能:1.學生入口
2.講師入口
3.管理入口
學生入口:1.選擇班級
2.選擇課程
3.交學費
4.查當作績

講師入口:1.查看班級
查看班級:a.查看班級成員
b.修改學員成績
2.管理班級:a.加入班級
b.退出班級

管理入口:1.建立講師
2.建立班級
3.建立課程
結構:Subject:bin ---enter.py ...程序入口,執行此文件進入程序

core ---main.py ...建立模板類和方法
---admin_enter.py ...管理員入口
---student_enter.py ...學生入口
---teacher_enter.py ...講師入口
---test.py ...查看全部文件信息裏的值

conf ---data.py ...數據讀寫的方法
---school.info 學校信息數據文件,存儲格式:{school_name:{"address": str, "city": str}}
---student.info 學生信息數據文件,存儲格式:{school_name:
{student_name:
{"pwd":self.pwd,"age": self.age, "sex": self.sex,"score":{"語文":90,"數學":80},"course": [], "classes": None,"fee_sign":0}}}
未作加入考試成績功能,全部在建立學生的時候默認給予成績"score":{"語文":90,"數學":80},"fee_sign":0爲繳費標誌,0爲未交費,1爲已繳費
---teacher.info 老師信息數據文件,存儲格式:{school_name:
{teacher_name:
{"pwd":self.pwd,"age": self.age, "sex": self.sex,"course": [], "classes": []}}}
---classes.info 班級信息數據文件,存儲格式:{school_name:
{classes_name:
{"teacher":[],"student":[],"course":[]}}}
---course.info 課程信息數據文件,存儲格式:{school_name:
{course_name:
{"cycle": cycle, "price": price,"teacher": [], "student": [], "classes": []}}}

使用方法:
1.先執行enter.py進入登陸界面
2.選擇管理,先建立講師或者課程,再建立班級,由於在建立班級時默認須要加入講師和課程
3.進入學生接口註冊學生,註冊後登陸選擇加入班級和課程,班級只會加入一個,第二次加入會替換第一次,課程能夠加入多個。加入課程後能夠交費。
4.進入講師入口

問題:
班級建立時添加課程和老師,只能添加一個,添加多個老師需進入講師入口添加班級,添加多個課程功能未實現。
學生添加一個課程後完成繳費,再添加一個課程再繳費會提示學費已結清。

流程圖:
代碼:
bin:

入口:enter.py
#!/usr/bin/env python
# -*-coding:utf-8-*-
# _author_=zh
import os
import sys
PATH=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0,PATH)
import core
import conf
#存學校的內存對象
school_list=[]
school_bj=core.main.School("北京學校","五里屯","北京")
school_sh=core.main.School("上海學校","黃浦江","上海")
school_bj.get_school()
school_sh.get_school()
school_list.append(school_bj)
school_list.append(school_sh)
INPUT_DICT={"1":core.student_enter.student_enter,
            "2":core.teacher_enter.teacher_enter,
            "3":core.admin_enter.admin_enter}
INFO='''\033[34;1m--*--Welcome To Subject System--*--
            1.學生
            2.講師
            3.管理
            9.退出\033[0m
'''
core.main.login_face(INFO,INPUT_DICT,school_list)
enter.py

core:
建立模板類和方法:main.py
#!/usr/bin/env python
# -*-coding:utf-8-*-
# _author_=zh
import conf
import core
class School(object):
    def __init__(self,name,address,city,):
        self.name=name
        self.address=address
        self.city=city

    def get_school(self):
        # 建立學校,並存入school.info
            school_dict = conf.data.read()
            school_dict[self.name] = {"address": self.address, "city": self.city}
            conf.data.write(school_dict)

    def get_class(self):
        # 建立班級
        # 數據存入class.info:{學校名稱:{班級名稱:{"teacher":[],"studenr":[],"course":[]}}}
        class_dict=conf.data.read("classes.info")
        null_dict = {}
        MODEL={"teacher":[],"student":[],"course":[]}
        class_name=input("\033[32;0m請輸入班級名稱:\033[0m").strip()
        if self.name not in class_dict.keys():
            null_dict[class_name]=MODEL
            class_dict[self.name]=null_dict
        else:
            class_dict[self.name][class_name]=MODEL
        #建立的時候加入課程和教師
        data_list=[self.name,class_name]
        conf.data.write(class_dict,"classes.info")
        view=core.student_enter.Student_view(data_list,"classes")
        view.pick("course.info","course")
        view.pick("teacher.info", "teacher")
        print("\33[31;0m建立成功!\33[0m")

    def get_course(self):
        # 建立課程,存儲方式與班級相同
        course_dict = conf.data.read("course.info")
        null_dict = {}
        course_name=input("\033[32;0m請輸入課程名稱:\033[0m").strip()
        cycle=input("\033[32;0m請輸入課程週期(單位:月)\033[0m").strip()
        price=input("\033[32;0m請輸入課程價格(單位:元)\033[0m").strip()
        MODEL={"cycle": cycle, "price": price,
               "teacher": [], "student": [], "classes": []}
        if self.name not in course_dict.keys():
            null_dict[course_name] =MODEL
            course_dict[self.name] = null_dict
        else:
            course_dict[self.name][course_name]=MODEL
        conf.data.write(course_dict, "course.info")
        print("\33[31;0m建立成功!\33[0m")

class People(object):
    #人類
    def __init__(self,name,age,sex,pwd):
        self.name=name
        self.age=age
        self.sex=sex
        self.pwd=pwd
        #數據存儲格式
        self.MODEL = {"pwd":self.pwd,"age": self.age, "sex": self.sex}

    def get_people(self,school_obj,data_address):
        '''
        建立學校裏任務的模板
        :param school_obj: 學校的對象
        :param data_address: 存儲文件名稱
        :return:
        '''
        people_dict = conf.data.read(data_address)
        null_dict = {}
        if school_obj.name not in people_dict.keys():
            null_dict[self.name] = self.MODEL
            people_dict[school_obj.name] = null_dict
        else:
            people_dict[school_obj.name][self.name] = self.MODEL
        conf.data.write(people_dict, data_address)
        print("\33[31;0m建立成功!\33[0m")

class Teacher(People):
    #老師
    def __init__(self,name,age,sex,pwd):
        super(Teacher,self).__init__(name,age,sex,pwd)
        # 數據存儲格式
        self.MODEL = {"pwd":self.pwd,"age": self.age, "sex": self.sex,"course": [], "classes": []}

class Students(People):
    #學生
    def __init__(self,name,age,sex,pwd):
        super(Students,self).__init__(name,age,sex,pwd)
        # 數據存儲格式    fee:學費狀態,0爲未交,1爲已繳
        self.MODEL = {"pwd":self.pwd,"age": self.age, "sex": self.sex,"score":{"語文":90,"數學":80},
                      "course": [], "classes": None,"fee_sign":0}


def login_face(info,input_dict,args=None):
    #界面展現功能模板
    INPUT_DICT = input_dict
    while True:
        INFO = info
        print(INFO)
        num = input("\033[32;0m請輸入序號選擇入口:\033[0m")
        if num=="0":
            break
        elif num=="9":
            exit()
        elif num in INPUT_DICT.keys():
            INPUT_DICT[num](args)
        else:
            print("\033[31;1m輸入錯誤,請從新輸入\033[0m")

def pick_school(obj):
    '''
    該方法用於選擇學校時調用
    :param obj: obj爲學校的對象列表
    :return: obj[num-1]選擇後的學校對象
    '''
    for i in obj:
        print("\33[34;1m%s.%s\33[0m"%(obj.index(i)+1,i.name))
    while True:
        num=input("\033[32;0m請選擇學校序號:\033[0m")
        if num.isdigit():
            num=int(num)
            if num in range(1,len(obj)+1):
                return obj[num-1]
            else:
                print("\033[31;1m輸入錯誤\033[0m")
        else:
            print("\033[31;1m輸入錯誤\033[0m")

def auth(obj,datafile):
    '''
     登陸驗證
    :param obj: obj爲學校的對象列表
    :param datafile: datafile爲存儲數據的文件名
    :return: data_list=[school_obj.name,name],登陸時選擇的學校名稱和登陸人員名稱
    '''
    school_obj=pick_school(obj)
    while True:
        name = input("\033[32;0m請輸入姓名:\033[0m").strip()
        pwd = input("\033[32;0m請輸入密碼:\033[0m").strip()
        data_dict=conf.data.read(datafile)
        if data_dict:
            if name in data_dict[school_obj.name].keys() and \
                pwd==data_dict[school_obj.name][name]["pwd"]:
                print("\033[32;0mWelcome,%s\033[0m"%name)
                data_list=[school_obj.name,name]
                #返回學校名稱和登陸人名稱
                return data_list
            else:
                print("\033[31;1m帳號或密碼錯誤\033[0m")
        else:
            print("\033[31;1m沒有數據,請先註冊!\033[0m")
            return []
main.py

管理入口:admin_enter.py

#!/usr/bin/env python
# -*-coding:utf-8-*-
# _author_=zh
import core
import conf
def admin_enter(obj):
    #管理員入口
    INPUT_DICT={"1":c_teather,"2":c_class,"3":c_course}
    INFO='''\033[34;1m1.建立講師
2.建立班級
3.建立課程
0.返回上一層
9.退出\033[0m'''
    core.main.login_face(INFO,INPUT_DICT,obj)

def c_teather(obj):
    #建立老師
    school_obj = core.main.pick_school(obj)
    name = input("\033[32;0m名字:\033[0m").strip()
    age = input("\033[32;0m年齡:\033[0m").strip()
    sex = input("\033[32;0m性別:\033[0m").strip()
    pwd=input("\033[32;0m密碼:\033[0m").strip()
    teacher_obj=core.main.Teacher(name,age,sex,pwd)
    teacher_obj.get_people(school_obj,"teacher.info")
def c_class(obj):
    #建立班級
    school_obj = core.main.pick_school(obj)
    school_obj.get_class()
def c_course(obj):
    #建立課程
    school_obj = core.main.pick_school(obj)
    school_obj.get_course()
admin_enter.py

學生入口:student_enter.py

#!/usr/bin/env python
# -*-coding:utf-8-*-
# _author_=zh
import core
import conf
def student_enter(obj):
    #學生入口
    INPUT_DICT = {"1": login, "2": logon}
    INFO = '''\033[34;1m1.註冊
2.登陸
0.返回上一層
9.退出\033[0m '''
    core.main.login_face(INFO, INPUT_DICT,obj)

def login(obj):
    #註冊
    school_obj = core.main.pick_school(obj)
    name = input("\033[32;0m名字:\033[0m").strip()
    age = input("\033[32;0m年齡:\033[0m").strip()
    sex = input("\033[32;0m性別:\033[0m").strip()
    pwd = input("\033[32;0m密碼:\033[0m").strip()
    student_obj = core.main.Students(name, age, sex,pwd)
    student_obj.get_people(school_obj, "student.info")
    print("請登陸:")
    logon(obj)

def logon(obj):
    #登陸
    data_list=core.main.auth(obj,"student.info")
    if  data_list:
        view = Student_view(data_list,"student")
        INFO = '''\033[34;1m1.選擇班級
2.選擇課程
3.交學費
4.查當作績
0.返回上一層
9.退出\033[0m'''
        while True:
            print(INFO)
            num = input("\033[32;0m請輸入序號選擇入口:\033[0m")
            if num == "0":
                break
            elif num == "9":
                exit()
            elif num=="1":
                view.pick("classes.info","classes")
            elif num=="2":
                view.pick("course.info", "course")
            elif num =="3":
                view.pay("course.info","course")
            elif num =="4":
                view.get_mark()
            else:
                print("\033[31;1m輸入錯誤,請從新輸入\033[0m")
    else:
        return

class Student_view(object):
    #學生視圖類
    def __init__(self,data_list,info_name):
        '''
        :param data_list: 調用core裏的auto登陸驗證時會返回學校名稱和登陸名稱的列表
        :param info_name: 打開文件的文件名稱
        '''
        self.school_name=data_list[0]
        self.name=data_list[1]
        self.info_name=info_name
        self.student_data = conf.data.read("%s.info"%self.info_name)

    def pick(self,datafile,choose):
        '''
        pick():選擇的接口,好比學生老師選擇班級,選擇課程,生成班級時選擇老師,選擇課程都調用此方法
        選擇後雙向添加,好比向班級里加入課程,在classes.info中"course"會加入選擇的課程,
        同時在course.info中的"classes"也會加入該班級
        :param datafile: 信息文件名稱
        :param choose: 選擇類型("class"或者"course")
        :return:
        '''
        data=conf.data.read(datafile)
        count=0
        key_dict={}
        try:
            for key in data[self.school_name]:
                count+=1
                print("\033[34;1m%s.%s\033[0m"%(count,key))
                key_dict[count]=key
            num=input("\033[32;0m選擇須要加入的序號:\033[0m").strip()
            if num.isdigit():
                num=int(num)
            if num in key_dict.keys():
                if type(self.student_data[self.school_name][self.name][choose]) is list:
                    self.student_data[self.school_name][self.name][choose].append(key_dict[num])
                else:
                    self.student_data[self.school_name][self.name][choose]=key_dict[num]
                if type(data[self.school_name][key_dict[num]][self.info_name]) is list:
                    data[self.school_name][key_dict[num]][self.info_name].append(self.name)
                else:
                    data[self.school_name][key_dict[num]][self.info_name] = (self.name)
                conf.data.write(self.student_data,"%s.info"%self.info_name)
                conf.data.write(data,datafile)
        except KeyError as e:
            print("請先建立講師和課程")


    def pay(self,datafile,choose):
        #支付學費
        if self.student_data[self.school_name][self.name]["fee_sign"]==0:
            course_list=self.student_data[self.school_name][self.name][choose]
            data = conf.data.read(datafile)
            fee=0
            for i in course_list:
                fee=fee+int(data[self.school_name][i]["price"])
            print("\033[32;0m課程總學費爲:%s\033[0m"%fee)
            num=input("\033[32;0m請輸入繳費金額:\033[0m").strip()
            if num.isdigit():
                num=int(num)
                if num==fee:
                    print("\033[31;1m繳費成功\033[0m")
                    self.student_data[self.school_name][self.name]["fee_sign"] =1
                    conf.data.write(self.student_data,"student.info")
                else:
                    print("\033[31;1m輸入錯誤\033[0m")
            else:
                print("\033[31;1m輸入錯誤\033[0m")
        else:
            print("\033[31;1m學費已結清\033[0m")

    def get_mark(self):
        #查當作績
        score_dict=self.student_data[self.school_name][self.name]["score"]
        for key,values in score_dict.items():
            print("%s:%s"%(key,values))
        print()
student_enter.py

講師入口:teacher_enter.py

#!/usr/bin/env python
# -*-coding:utf-8-*-
# _author_=zh
import core
import conf
def teacher_enter(obj):
    teacher_list=core.main.auth(obj,"teacher.info")
    if teacher_list:
        INPUT_DICT={"1":see,"2":manage}
        INFO='''\033[34;1m1.查看班級
2.管理班級
0.返回上一層
9.退出\033[0m'''
        core.main.login_face(INFO, INPUT_DICT,teacher_list)
    else:
        return

def see(teacher_list):
    INPUT_DICT = {"1": see_student, "2": alter}
    INFO = '''\033[34;1m1.查看班級成員
2.修改學員成績
0.返回上一層
9.退出\033[0m'''
    core.main.login_face(INFO, INPUT_DICT, teacher_list)

def choose_class(teacher_list):
    #選擇班級的模板,返回班級列表
    #teacher_list:調用core.main.auto()登陸驗證方法返回的學校姓名和登陸名稱的列表
    school_name = teacher_list[0]
    teacher_name = teacher_list[1]
    teacher_data = conf.data.read("teacher.info")
    class_list=teacher_data[school_name][teacher_name]["classes"]
    for i in class_list:
        print("\033[34;1m%s.%s\033[0m" % (class_list.index(i)+1, i))
    return class_list

def see_student(teacher_list):
    #查看班級成員
    class_list=choose_class(teacher_list)
    num = input("\033[32;0m選擇查看的班級序號:\033[0m").strip()
    if num.isdigit():
        num = int(num)
        if num in range(1,len(class_list)+1):
            class_data = conf.data.read("classes.info")
            student_list=class_data[teacher_list[0]][class_list[num-1]]["student"]
            if student_list:
                for i in student_list:
                    print("\033[34;1m%s.%s\033[0m" % (student_list.index(i) + 1, i))
                print()
            else:
                print("\033[31;1m未加入學生\033[0m")
            return student_list
        else:
            print("\033[31;1m輸入錯誤\033[0m")
            return []
    else:
        print("\033[31;1m輸入錯誤\033[0m")
        return []


def alter(teacher_list):
    #修改學生成績
    student_list=see_student(teacher_list)
    num=input("\033[32;0m選擇修改的學生序號:\033[0m").strip()
    if num.isdigit():
        num = int(num)
        if num in range(1, len(student_list) + 1):
            student_data = conf.data.read("student.info")
            score_dict=student_data[teacher_list[0]][student_list[num-1]]["score"]
            for key,values in score_dict.items():
                print("\033[34;1m%s:%s\033[0m"%(key,values))
            course=input("\033[32;0m輸入須要修改的課程名稱:\033[0m")
            score=input("\033[32;0m修改後的成績:\033[0m")
            score_dict[course]=score
            conf.data.write(student_data,"student.info")
            print("\033[31;1m修改爲功\033[0m")
        else:
            print("\033[31;1m輸入錯誤\033[0m")
    else:
        print("\033[31;1m輸入錯誤\033[0m")

def manage(teacher_list):
    #管理班級
    INPUT_DICT = {"1": join, "2": quit}
    INFO = '''\033[34;1m1.加入班級
2.退出班級
0.返回上一層
9.退出\033[0m'''
    core.main.login_face(INFO, INPUT_DICT, teacher_list)

def join(teacher_list):
    #加入班級
    view = core.student_enter.Student_view(teacher_list, "teacher")
    view.pick("classes.info", "classes")

def quit(teacher_list):
    '''
    退出班級,移除teacher.info中「classes」:[]中的班級,
     同時移除classes.info中該班級裏"teacher":[]中的該老師
    :param teacher_list: 調用core.main.auto()登陸驗證方法返回的學校姓名和登陸名稱的列表
    :return:
    '''
    class_list = choose_class(teacher_list)
    print(class_list)
    num = input("\033[32;0m選擇想退出的班級序號:\033[0m").strip()
    if num.isdigit():
        num = int(num)
        if num in range(1, len(class_list) + 1):
            teacher_data = conf.data.read("teacher.info")
            class_data=conf.data.read("classes.info")
            teacher_data[teacher_list[0]][teacher_list[1]]["classes"].remove(class_list[num-1])
            class_data[teacher_list[0]][class_list[num-1]]["teacher"].remove(teacher_list[1])
            conf.data.write(teacher_data,"teacher.info")
            conf.data.write(class_data, "classes.info")
            print("\033[31;1m刪除成功\033[0m")
        else:
            print("\033[31;1m輸入錯誤\033[0m")
    else:
        print("\033[31;1m輸入錯誤\033[0m")
teacher_enter.py

測試:test.py

import os
import sys
PATH=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0,PATH)
import conf
school_data=conf.data.read("school.info")
classes_data=conf.data.read("classes.info")
course_data=conf.data.read("course.info")
teacher_data=conf.data.read("teacher.info")
student_data=conf.data.read("student.info")
print("school_data:",school_data)
print("classes_data:",classes_data)
print("course_data:",course_data)
print("teacher_data:",teacher_data)
print("student_data:",student_data)
test.py

 

conf:

數據讀寫:data.py

#!/usr/bin/env python
# -*-coding:utf-8-*-
# _author_=zh

import pickle
import os
PATH=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))+os.sep+"conf"
def write(obj,name="school.info"):
        pickle.dump(obj,open("%s%s%s"%(PATH,os.sep,name), "wb"))

def read(name="school.info"):
    if os.path.exists("%s%s%s" % (PATH, os.sep,name)):
        school_dict=pickle.load(open("%s%s%s"%(PATH,os.sep,name), "rb"))
        return school_dict
    else:
        return {}
data.py
相關文章
相關標籤/搜索