首页 > 代码库 > [terry笔记]学校管理系统

[terry笔记]学校管理系统

如下是要求:

# 角色:学校、学员、课程、讲师
# 要求:
# 1. 创建北京、上海 2 所学校
# 2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开
# 3. 课程包含,周期,价格,通过学校创建课程
# 4. 通过学校创建班级, 班级关联课程、讲师
# 5. 创建学员时,选择学校,关联班级
# 5. 创建讲师角色时要关联学校,
# 6. 提供两个角色接口
# 6.1 学员视图, 可以注册, 交学费, 选择班级,
# 6.2 讲师视图, 讲师可管理自己的班级, 上课时选择班级, 查看班级学员列表 , 修改所管理的学员的成绩
# 6.3 管理视图,创建讲师, 创建班级,创建课程
# 7. 上面的操作产生的数据都通过pickle序列化保存到文件里

 

如下是目录结构:

技术分享

 

start.py

技术分享
1 import sys, os, pickle
2 sys.path.append(os.path.dirname(os.path.dirname(__file__)) + "\\" + "core")
3 from main import Main
4 
5 obj = Main()
6 obj.run()
View Code

 

init_db.py

技术分享
 1 # 此程序作为初始化数据库
 2 import sys,os
 3 sys.path.append(os.path.dirname(os.path.dirname(__file__))+"\\"+"module")
 4 from pickle_file import pickle_wb,pickle_rb
 5 
 6 teacher_db = [["学校","讲师","年龄","性别"]]
 7 classes_db = [["班级","学校","课程","讲师","周期","价格"]]
 8 stu_db = [["编号","姓名","年龄","性别","学费","班级"]]
 9 
10 def init_db():
11     if "teacher_db" not in os.listdir(os.path.dirname(os.path.dirname(__file__))+"\\"+"db"):
12         pickle_wb("teacher_db", teacher_db)
13     else:
14         pass
15 
16     if "classes_db" not in os.listdir(os.path.dirname(os.path.dirname(__file__))+"\\"+"db"):
17         pickle_wb("classes_db", classes_db)
18     else:
19         pass
20 
21     if "stu_db" not in os.listdir(os.path.dirname(os.path.dirname(__file__))+"\\"+"db"):
22         pickle_wb("stu_db", stu_db)
23     else:
24         pass
View Code

 

main.py

技术分享
  1 # 角色:学校、学员、课程、讲师
  2 # 要求:
  3 # 1. 创建北京、上海 2 所学校
  4 # 2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开
  5 # 3. 课程包含,周期,价格,通过学校创建课程
  6 # 4. 通过学校创建班级, 班级关联课程、讲师
  7 # 5. 创建学员时,选择学校,关联班级
  8 # 5. 创建讲师角色时要关联学校,
  9 # 6. 提供两个角色接口
 10 # 6.1 学员视图, 可以注册, 交学费, 选择班级,
 11 # 6.2 讲师视图, 讲师可管理自己的班级, 上课时选择班级, 查看班级学员列表 , 修改所管理的学员的成绩
 12 # 6.3 管理视图,创建讲师, 创建班级,创建课程
 13 # 7. 上面的操作产生的数据都通过pickle序列化保存到文件里
 14 
 15 class Main(object):
 16     def __init__(self):
 17         pass
 18 
 19     def run(self):
 20 
 21         import sys,os,pickle
 22         sys.path.append(os.path.dirname(os.path.dirname(__file__))+"\\"+"module")
 23         from init_db import init_db
 24         from school import School
 25         from lesson import Lesson
 26         from classes import Classes
 27         from school_member import Schoolmember,Teacher,Student
 28         from pickle_file import pickle_wb,pickle_rb
 29 
 30 
 31         msg = """
 32             学校管理系统
 33             1、学校管理
 34             2、讲师管理
 35             3、学员管理
 36             4、退出
 37         """
 38         mgr = """
 39             1、创建讲师
 40             2、创建班级
 41             3、创建课程
 42             4、查看讲师信息
 43             5、查看班级、课程信息
 44             6、返回上一级
 45         """
 46         stu = """
 47             1、注册
 48             2、交学费
 49             3、选择班级
 50             4、查看学员信息
 51             5、返回上一级
 52         """
 53 
 54         init_db()
 55         school_bj = School("北京")
 56         school_sh = School("上海")
 57         lesson_linux = Lesson("linux",10000,"6 month")
 58         lesson_python = Lesson("python",11000,"8 month")
 59         lesson_go = Lesson("go",8000,"6 month")
 60         flag = True
 61         while flag:
 62             print(msg)
 63             choice = input("请选择系统 :")
 64             if choice == "1":
 65                 while True:
 66                     print(mgr)
 67                     choice = input("请选择功能 :")
 68                     if choice == "1":
 69                         print("创建讲师 :\n请选择学校:\n1、北京\n2、上海")
 70                         num = 0
 71                         while True:
 72                             school_num = input("请选择学校 :")
 73                             if num < 2:
 74                                 if school_num == "1":
 75                                     school_choice = school_bj.school_name
 76                                     break
 77                                 elif school_num == "2":
 78                                     school_choice = school_sh.school_name
 79                                     break
 80                                 else:
 81                                     print("请输入正确编号!")
 82                                     num += 1
 83                             else:
 84                                 print("尝试次数过多!")
 85                                 exit()
 86                         teacher_name = input("请输入教师名字 :")
 87                         age = input("请输入教师年龄 :")
 88                         sex = input("请输入教师性别 :")
 89                         teacher_data =http://www.mamicode.com/ school_bj.create_teacher(school_choice,teacher_name,age,sex)
 90                         teacher_db_data = http://www.mamicode.com/pickle_rb("teacher_db")
 91                         teacher_db_data.append(teacher_data)
 92                         pickle_wb("teacher_db",teacher_db_data)
 93                     elif choice == "2":
 94                         classes_data =http://www.mamicode.com/ []
 95                         c_name_list = []
 96                         classes_db_data = http://www.mamicode.com/pickle_rb("classes_db")
 97                         while True:
 98                             c_name = input("\n创建班级\n请输入班级编号(格式001) :")
 99                             for i in classes_db_data:
100                                 c_name_list.append(i[0])
101                             if c_name in c_name_list:
102                                 print("班级名称已存在!")
103                                 print("已有如下班级:")
104                                 for j in c_name_list:
105                                     print(j)
106                             else:break
107                         school_num = input("\n1、北京(linux与python课程)\n2、上海(go课程)\n请选择学校 :")
108                         lesson_choice = ""
109                         if school_num == "1":
110                             school_choice = school_bj.school_name
111                             lesson_num = input("\n1、linux\n2、python\n请选择课程 :")
112                             if lesson_num == "1":
113                                 lesson_choice = lesson_linux.lesson_name
114                                 lesson_choice_cycle = lesson_linux.cycle
115                                 lesson_choice_price = lesson_linux.price
116                             elif lesson_num == "2":
117                                 lesson_choice = lesson_python.lesson_name
118                                 lesson_choice_cycle = lesson_python.cycle
119                                 lesson_choice_price = lesson_python.price
120                             else:
121                                 print("没有这门课程")
122                                 exit()
123                         elif school_num == "2":
124                             school_choice = school_sh.school_name
125                             lesson_choice = lesson_go.lesson_name
126                             lesson_choice_cycle = lesson_go.cycle
127                             lesson_choice_price = lesson_go.price
128                         else:
129                             print("没有此编号!")
130                             exit()
131                         teacher_data = http://www.mamicode.com/pickle_rb("teacher_db")
132                         teacher_name = {}
133                         for i,ele in enumerate(teacher_data):
134                             teacher_name[i] = ele[1]
135                         for key,value in teacher_name.items():
136                             if key == 0:continue
137                             else:print("%s、%s" % (key,value))
138                         teacher_choice = input("请选择讲师 :")
139                         classes_data.append(c_name)
140                         classes_data.append(school_choice)
141                         classes_data.append(lesson_choice)
142                         classes_data.append(teacher_name[int(teacher_choice)])
143                         classes_data.append(lesson_choice_cycle)
144                         classes_data.append(lesson_choice_price)
145                         classes_db_data = http://www.mamicode.com/pickle_rb("classes_db")
146                         classes_db_data.append(classes_data)
147                         pickle_wb("classes_db",classes_db_data)
148                     elif choice == "3":
149                         classes_data =http://www.mamicode.com/ []
150                         c_name_list = []
151                         classes_db_data = http://www.mamicode.com/pickle_rb("classes_db")
152                         school_num = input("\n1、北京(linux与python课程)\n2、上海(go课程)\n请选择学校 :")
153                         lesson_choice = ""
154                         if school_num == "1":
155                             school_choice = school_bj.school_name
156                             lesson_num = input("\n1、linux\n2、python\n请选择课程 :")
157                             if lesson_num == "1":
158                                 lesson_choice = lesson_linux.lesson_name
159                                 lesson_choice_cycle = lesson_linux.cycle
160                                 lesson_choice_price = lesson_linux.price
161                             elif lesson_num == "2":
162                                 lesson_choice = lesson_python.lesson_name
163                                 lesson_choice_cycle = lesson_python.cycle
164                                 lesson_choice_price = lesson_python.price
165                             else:
166                                 print("没有这门课程")
167                                 exit()
168                         elif school_num == "2":
169                             school_choice = school_sh.school_name
170                             lesson_choice = lesson_go.lesson_name
171                             lesson_choice_cycle = lesson_go.cycle
172                             lesson_choice_price = lesson_go.price
173                         else:
174                             print("没有此编号!")
175                             exit()
176                         while True:
177                             c_name = input("\n创建班级\n请输入班级编号(格式001) :")
178                             for i in classes_db_data:
179                                 c_name_list.append(i[0])
180                             if c_name in c_name_list:
181                                 print("班级名称已存在!")
182                                 print("已有如下班级:")
183                                 for j in c_name_list:
184                                     print(j)
185                             else:break
186                         teacher_data = http://www.mamicode.com/pickle_rb("teacher_db")
187                         teacher_name = {}
188                         for i,ele in enumerate(teacher_data):
189                             teacher_name[i] = ele[1]
190                         for key,value in teacher_name.items():
191                             if key == 0:continue
192                             else:print("%s、%s" % (key,value))
193                         teacher_choice = input("请选择讲师 :")
194                         classes_data.append(c_name)
195                         classes_data.append(school_choice)
196                         classes_data.append(lesson_choice)
197                         classes_data.append(teacher_name[int(teacher_choice)])
198                         classes_data.append(lesson_choice_cycle)
199                         classes_data.append(lesson_choice_price)
200                         classes_db_data = http://www.mamicode.com/pickle_rb("classes_db")
201                         classes_db_data.append(classes_data)
202                         pickle_wb("classes_db",classes_db_data)
203                     elif choice == "4":
204                         teacher_data = http://www.mamicode.com/pickle_rb("teacher_db")
205                         for i,item in enumerate(teacher_data):
206                             print(i,item)
207                         input("回车返回上级菜单。")
208                     elif choice == "5":
209                         classes_db_data = http://www.mamicode.com/pickle_rb("classes_db")
210                         for i,item in enumerate(classes_db_data):
211                             print(i,item)
212                         input("回车返回上级菜单。")
213                     elif choice == "6":
214                         break
215             elif choice == "4":
216                 exit()
217             elif choice == "3":
218                 while True:
219                     print(stu)
220                     choice = input("请选择功能 :")
221                     if choice == "1":
222                         stu_list = []
223                         stu_db_data = http://www.mamicode.com/pickle_rb("stu_db")
224                         len_stu_db_data =http://www.mamicode.com/ len(stu_db_data)
225                         stu_list.append("00"+str(len_stu_db_data))
226                         stu_name = input("请输入学生姓名 :")
227                         stu_age = input("请输入学生年龄 :")
228                         stu_sex = input("请输入学生性别 :")
229                         stu_data =http://www.mamicode.com/ Student(stu_name,stu_age,stu_sex)
230                         stu_list.append(stu_data.name)
231                         stu_list.append(stu_data.age)
232                         stu_list.append(stu_data.sex)
233                         stu_list.append("未付款")
234                         stu_list.append("未选择")
235                         stu_db_data = http://www.mamicode.com/pickle_rb("stu_db")
236                         stu_db_data.append(stu_list)
237                         pickle_wb("stu_db",stu_db_data)
238 
239                     elif choice == "2":
240                         stu_db_data = http://www.mamicode.com/pickle_rb("stu_db")
241                         stu_unpay = []
242                         stu_unpay_id = []
243                         stu_id = []
244                         for i in stu_db_data:
245                             if i[4] == "未付款":
246                                 stu_unpay_id.append(i[0])
247                                 stu_unpay.append(i)
248                         if len(stu_unpay_id) == 0:
249                             a = input("不存在未付款的学员,回车键返回。")
250                             break
251                         else:
252                             print("如下同学还未付款 :")
253                             for i in stu_unpay:
254                                 print(i)
255                         for i in stu_db_data:
256                             stu_id.append(i[0])
257                         pay_id = input("\n请输入付款学员的编号 :")
258                         if pay_id not in stu_id:
259                             a = input("没有这个学员编号,请输入正确学员编号,回车键返回")
260                             break
261                         elif pay_id in stu_id and pay_id not in stu_unpay_id:
262                             a = input("这个学员已付款,回车键返回")
263                         elif pay_id in stu_unpay_id:
264                             for i in stu_db_data:
265                                 if pay_id == i[0]:
266                                     i[4] = "已付款"
267                         pickle_wb("stu_db",stu_db_data)
268                         a = input("编号:%s,此学员已付款完毕,回车键返回。" % (pay_id))
269 
270                     elif choice == "3":
271                         stu_db_data = http://www.mamicode.com/pickle_rb("stu_db")
272                         stu_unchoice = []
273                         stu_unchoice_id = []
274                         stu_id = []
275                         classes_db_data_id = []
276                         for i in stu_db_data:
277                             if i[5] == "未选择":
278                                 stu_unchoice_id.append(i[0])
279                                 stu_unchoice.append(i)
280                         if len(stu_unchoice_id) == 0:
281                             a = input("不存在未选课的学员,回车键返回。")
282                             break
283                         else:
284                             print("如下同学还未选课 :")
285                             for i in stu_unchoice:
286                                 print(i)
287                         for i in stu_db_data:
288                             stu_id.append(i[0])
289                         choice_id = input("\n请输入选课学员的编号 :")
290                         print("\n")
291                         if choice_id not in stu_id:
292                             a = input("没有这个学员编号,请输入正确学员编号,回车键返回")
293                             break
294                         elif choice_id in stu_id and choice_id not in stu_unchoice_id:
295                             a = input("这个学员已选课,回车键返回")
296                         elif choice_id in stu_unchoice_id:
297                             classes_db_data = http://www.mamicode.com/pickle_rb("classes_db")
298                             for i,item in enumerate(classes_db_data):
299                                 classes_db_data_id.append(item[0])
300                                 print(i,item)
301                             classes_id = input("请选择班级编号(如:001) :")
302                             if classes_id not in classes_db_data_id:
303                                 a = input("没有这个班级,请输入正确班级号,回车键返回。")
304                                 break
305                             else:
306                                 for i in stu_db_data:
307                                     if choice_id == i[0]:
308                                         i[5] = classes_id
309                             pickle_wb("stu_db",stu_db_data)
310                             a = input("编号:%s学员,已选择班级%s,回车键返回" % (choice_id,classes_id))
311 
312                     elif choice == "4":
313                         stu_data = http://www.mamicode.com/pickle_rb("stu_db")
314                         for i,item in enumerate(stu_data):
315                             print(i,item)
316                         input("回车返回上级菜单。")
317                     elif choice == "5":
318                         break
319             elif choice == "2":
320                 pass
321             else:
322                 a = input("请输入正确编号!按回车键返回。")
323         return
324 
325 # [‘姓名‘, ‘年龄‘, ‘性别‘, ‘学费‘, ‘班级‘]
View Code

 

classes.py

技术分享
1 class Classes(object):
2     def __init__(self,classes_name):
3         self.classes_name = classes_name
View Code

 

lesson.py

技术分享
1 class Lesson(object):
2     def __init__(self,lesson_name,price,cycle):
3         self.lesson_name = lesson_name
4         self.price = price
5         self.cycle = cycle
View Code

 

pickle_file.py

技术分享
 1 import pickle
 2 import os
 3 
 4 def pickle_wb(file_name,data):
 5     f = open(os.path.dirname(os.path.dirname(__file__))+"\\"+"db"+"\\"+file_name,"wb")
 6     f.write(pickle.dumps(data))
 7     f.close()
 8     return
 9 
10 
11 def pickle_rb(file_name):
12     f = open(os.path.dirname(os.path.dirname(__file__))+"\\"+"db"+"\\"+file_name,"rb")
13     data =http://www.mamicode.com/ pickle.loads(f.read())
14     return data
View Code

 

school.py

技术分享
 1 class School(object):
 2     def __init__(self,school_name):
 3         self.school_name = school_name
 4 
 5     def create_teacher(self,school_name,teacher_name,age,sex):
 6         teacher_data =http://www.mamicode.com/ [school_name,teacher_name,age,sex]
 7         return teacher_data
 8 
 9     def create_lesson(self,school_name,lesson_name,price,cycle):
10         lesson_data =http://www.mamicode.com/ [school_name,lesson_name,price,cycle]
11         return lesson_data
View Code

 

school_member.py

技术分享
 1 class Schoolmember(object):
 2     def __init__(self,name,age,sex):
 3         self.name = name
 4         self.age = age
 5         self.sex = sex
 6 
 7 class Teacher(Schoolmember):
 8     def __init__(self,name,age,sex):
 9         super(Teacher,self).__init__(name,age,sex)
10 
11 class Student(Schoolmember):
12     def __index__(self,name,age,sex):
13         super(Student,self).__init__(name,age,sex)
View Code

 

 

其实是一个很低端的版本,学习类,但是感觉写着写着感觉有点跑偏了。

[terry笔记]学校管理系统