[terry笔记]学校管理系统

Posted terry - 充满着能量

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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 = school_bj.create_teacher(school_choice,teacher_name,age,sex)
 90                         teacher_db_data = 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 = []
 95                         c_name_list = []
 96                         classes_db_data = 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 = 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 = 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 = []
150                         c_name_list = []
151                         classes_db_data = 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 = 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 = 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 = 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 = 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 = pickle_rb("stu_db")
224                         len_stu_db_data = 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 = 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 = 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 = 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] == "未付款以上是关于[terry笔记]学校管理系统的主要内容,如果未能解决你的问题,请参考以下文章

[terry笔记]文件操作

[terry笔记]对人员列表文件进行数据库操作

人物Terry Lin: 商业智能(BI)让会计与财务管理事半功倍

学习笔记:python3,代码片段(2017)

为啥此代码片段返回意外结果?

Oracle-常用数据库对象笔记(片段)