本节作业: 选课系统
角色:学校、学员、课程、讲师
要求:
1. 创建北京、上海 2 所学校
2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开
3. 课程包含,周期,价格,通过学校创建课程
4. 通过学校创建班级, 班级关联课程、讲师
5. 创建学员时,选择学校,关联班级
5. 创建讲师角色时要关联学校,
6. 提供两个角色接口
6.1 学员视图, 可以注册, 交学费, 选择班级,
6.2 讲师视图, 讲师可管理自己的班级, 上课时选择班级, 查看班级学员列表 , 修改所管理的学员的成绩
6.3 管理视图,创建讲师, 创建班级,创建课程
7. 上面的操作产生的数据都通过pickle序列化保存到文件里
这几天烦心事情太多了,没法很好的专注,陆陆续续写了一个周。
我问了下同事,他们说他们初学的时候也就是一天就能写好,很受伤。
目前只有序列化这里没做,但是有思路了,有了实现的方法。写在最后边
1 # coding=utf-8 2 import time 3 import pickle 4 5 6 def log(a): 7 log_time = time.strftime(‘%Y-%m-%d %H:%M:%S‘, time.localtime(time.time())) 8 b = str(log_time) 9 c = str(a) + str(b) + ‘\n‘ 10 with open(‘log.text‘, ‘ab‘)as s: 11 s.write(pickle.dumps(c)) 12 13 class School(object): 14 def __init__(self, name, addr, city): 15 self.name = name # 这个名字是学校的 16 self.addr = addr # 办学地址 17 self.city = city # 办学城市 18 self.teacher_list = [] # 老师 19 self.student_list = [] # 学生 20 self.courese_list = [] # 开设课程 21 self.grades_list = [] # 班级 22 self.save_stud_id = [] # 储存stduID,不知道以后能不能用的,先创建 23 self.save_stud_pwd = [] 24 self.grades_name = [] 25 self.courese_name = [] 26 self.teacher_name = [] 27 self.student_name = [] 28 29 def creation_techer(self, teacher_obj): 30 a = ‘为 %s 老师办理上岗‘ % teacher_obj.name # 这个名字是实力类的 31 print(a) 32 log(a) 33 self.teacher_list.append(teacher_obj) 34 self.teacher_name.append(teacher_obj.name) 35 36 def baocun_studentId(self, obj_stuent): 37 print(‘为%s 同学办理入学手续‘ % obj_stuent.name) # 这里的名字也是实例的名字 38 self.student_list.append(obj_stuent) 39 self.student_name.append(obj_stuent.name) 40 self.save_stud_id.append(obj_stuent.stud_id) 41 42 def chuangjian_laoshi(self): 43 pass 44 45 def creation_course(self, course_type, pice, time): # 创建课程 46 a = ‘创建课程%s‘ % course_type 47 print(a) 48 self.courese_list.append(Course(course_type, pice, time)) 49 self.courese_name.append(course_type) 50 log(a) 51 52 def creation_grade(self, grade_name): # 创建班级 53 a = ‘创建班级%s‘ % grade_name 54 log(a) 55 self.grades_list.append(Grade(grade_name)) # 把类加进去了 56 self.grades_name.append(grade_name) # 保存班级姓名 57 def tell_school(self): #self, name, addr, city): 58 a = (‘‘‘ 59 ----info of School:%s---- 60 Name:%s 61 Addr:%s 62 City:%s 63 Course:%s 64 Grade:%s 65 ‘‘‘ % (self.name, self.name, self.addr, self.city,self.courese_name,self.grades_name)) 66 print(a) 67 log(a) 68 69 class School_number(object): 70 def __int__(self, name, age, sex): 71 self.name = name 72 self.age = age 73 self.sex = sex 74 75 76 class Course(): # 课程 77 def __init__(self, type, price, time): 78 self.type = type 79 self.price = price 80 self.time = time 81 82 def tell(self): 83 a = (‘‘‘ 84 ----info of Course:%s---- 85 Type:%s 86 Price:%s 87 Time:%s 88 ‘‘‘ % (self.type, self.type, self.price, self.time)) 89 print(a) 90 # f = open(‘teacher_acount.text‘, ‘ab+‘) 91 # f.write(pickle.dumps(a)) 92 # f.close() 93 94 95 class Grade(): # 班级 这里再试试 96 def __init__(self, grade_name): 97 # super(Course,self).__int__(type) #班级关联课程跟讲师 98 self.grade_name = grade_name 99 # self.grade_all=[] 100 self.courese_type = [] 101 self.teacher_grade = [] 102 self.student_grade = [] 103 self.student_grade_name=[] #用于老师视图显示班级信息 104 self.teacher_grade_name=[] #用于老师视图显示班级信息 105 106 def add_course(self, obj_course): 107 self.courese_type.append(obj_course.type) 108 print(‘%s添加课程%s‘ % (self.grade_name, obj_course.type)) 109 110 def add_student(self, obj_stduent): 111 self.courese_type.append(obj_stduent.courese_class_student) #添加学生选择的课程 112 self.student_grade.append(obj_stduent) 113 self.student_grade_name.append(obj_stduent.name) 114 print(‘添加%s到班级学生列表‘ % obj_stduent.name) 115 116 def add_teacher(self, obj_teancher): 117 self.teacher_grade.append(obj_teancher) 118 self.teacher_grade_name.append(obj_teancher.name) 119 print(‘添加%s到班级老师列表‘ % obj_teancher.name) 120 121 def tell_student_grade(self): 122 for index, i in enumerate(self.student_grade): 123 print(self.student_grade[index].name,‘in garde %s‘%self.grade_name) 124 125 def teall_teacher_grade(self): 126 for index, i in enumerate(self.teacher_grade): 127 print(self.teacher_grade[index].name,‘in garde %s‘%self.grade_name) 128 129 130 class Student(School, Grade, Course): 131 def __init__(self, name, age, sex, stud_id, stud_pwd, money): 132 # Grade.__int__(self,type) 133 # super(Student, self).__init__(courese) # 关联班级 134 self.name = name 135 self.age = age 136 self.sex = sex 137 self.stud_id = stud_id 138 self.stud_pwd = stud_pwd 139 self.money = money 140 self.courese_class_student = [] #学生选的课程 141 self.grade_class_student = [] #学生加入的班级 142 143 def serch_school_and_enroll(self, obj_serch_school, obj_student): # 选择实例学校 144 print(‘选择学校%s‘ % obj_serch_school.name) 145 obj_serch_school.save_stud_id.append(self.stud_id) 146 obj_serch_school.save_stud_pwd.append(self.stud_pwd) 147 obj_serch_school.student_list.append(obj_student) 148 obj_serch_school.student_name.append(obj_student.name) 149 print(‘为%s 同学办理入学手续‘ % self.name) 150 151 # def zhuc_student(self,obj_school,obj_student): 152 # 153 # print(‘为%s 同学办理入学手续‘%obj_student.name) 154 155 def serh_grade_student(self, obj_student,obj_grade): #这里我改了一下,这里不通顺 156 print(‘录入班级%s‘ % obj_grade.grade_name) 157 obj_grade.student_grade_name.append(self.name) # 添加班级名字到班级类文件夹$$$$$$$$$$$$$$$$$$$$$$$ 158 obj_grade.student_grade.append(obj_student) #添加实类到班级,好像没大有用 159 self.grade_class_student.append(obj_grade.grade_name) 160 print(‘班级%s选择成功,已将班级信息添加到班级类,学生类‘%obj_grade.grade_name) 161 162 def serch_courese_student(self, obj_courese): # 这里选择课程也是实例 163 print(‘%s选择课程%s‘ % (self.name, obj_courese.type)) 164 print(‘您选择的课程价格为%s,周期为%s‘ % (obj_courese.price, obj_courese.time)) 165 self.courese_class_student.append(obj_courese.type) 166 167 def pay_courese_price(self, obj_course): 168 print(‘正在支付学费%s‘ % obj_course.price) 169 time.sleep(3) 170 self.money = float(self.money) - float(obj_course.price) 171 print(‘还剩学费%s‘ % self.money) 172 173 174 def tell(self): 175 a = (‘‘‘ 176 ----info of Student:%s---- 177 Name:%s 178 Age:%s 179 Sex:%s 180 Student_ID:%s 181 Money:%s 182 Grade:%s 183 Course:%s 184 ‘‘‘ % (self.name, self.name, self.age, self.sex, self.stud_id, self.money, self.grade_class_student, 185 self.courese_class_student)) 186 print(a) 187 f = open(‘student_acount.text‘, ‘wb+‘) 188 f.write(pickle.dumps(a)) 189 f.close() 190 191 192 class Teacher(School_number, Grade): # 这里不知道对不对,我不继承学校,继承了学校成员,课程,班级 193 def __init__(self, name, age, sex): 194 super(Teacher, self).__int__(name, age, sex) ####我曹,这里是int!!!! 195 self.grade_teacher = [] #老师加入的班级 196 self.courese_teacher = [] #老师教的课程 197 198 def serch_courese_teacher(self, obj_courese): 199 print(‘%s老师选择课程%s‘ % (self.name, obj_courese.type)) 200 self.courese_teacher.append(obj_courese.type) 201 202 def serch_grade_teacher(self, obj_garde): 203 print(‘%s老师选择班级%s‘ % (self.name, obj_garde.grade_name)) 204 self.grade_teacher.append(obj_garde.grade_name) 205 206 def check_grades(self): 207 print(‘%s查看班级列表\n%s‘ % (self.name, self.grade_teacher)) 208 209 def check_student_grade_student(selfs, obj_grades): 210 print(‘%s查看%s学生列表\n%s‘ % (selfs.name, obj_grades.grade_name, obj_grades.student_grade)) ##这里不对,一会再屡屡, 211 212 def rec_student_score(self): # 修改分数 213 pass 214 215 def teaching(self, obj_grade,obj_course): 216 a=print(‘%s选择%s班级,上%s课程‘ % (self.name, obj_grade.grade_name,obj_course.type)) 217 print(a) 218 log(a) 219 def tell(self): 220 a = (‘‘‘ 221 ----info of Teacher:%s---- 222 Name:%s 223 Age:%s 224 Sex:%s 225 Course:%s 226 Grade:%s 227 ‘‘‘ % (self.name, self.name, self.age, self.sex, self.courese_teacher, self.grade_teacher)) 228 print(a) 229 # f = open(‘teacher_acount.text‘, ‘ab+‘) 230 # f.write(pickle.dumps(a)) 231 # f.close() 232 233 234 # 创建两所学校 235 school_bj = School(‘北京python‘, ‘海淀‘, ‘beijing‘) 236 school_sh = School(‘上海python‘, ‘浦东‘, ‘shanghai‘) 237 # 创建三个课程,其中lunix,python在北京,go在上海 238 school_bj.creation_course(‘lunix‘, ‘5000‘, ‘30day‘) 239 lunix = school_bj.courese_list[0] 240 school_bj.creation_course(‘python‘, ‘15000‘, ‘90day‘) 241 python = school_bj.courese_list[1] 242 school_sh.creation_course(‘go‘, ‘10000‘, ‘60day‘) 243 go = school_sh.courese_list[0] 244 # 创建三位老师,给三个选择擅长课程 245 zhanggavin = Teacher(‘zhanggavin‘, ‘33‘, ‘M‘) 246 zhanggavin.serch_courese_teacher(lunix) 247 zhanggavin.serch_courese_teacher(python) 248 egbert = Teacher(‘egbert‘, ‘30‘, ‘m‘) 249 egbert.serch_courese_teacher(lunix) 250 egbert.serch_courese_teacher(python) 251 slem = Teacher(‘slem‘, ‘30‘, ‘w‘) 252 slem.serch_courese_teacher(go) 253 # 为三位老师注册学校 254 school_bj.creation_techer(zhanggavin) 255 school_bj.creation_techer(egbert) 256 school_sh.creation_techer(slem) 257 # 创建班级三个班级,北方的教python,liunix,南方的教go 258 school_bj.creation_grade(‘1n1b_python_lunix‘) 259 yin1b = school_bj.grades_list[0] 260 school_bj.creation_grade(‘2n1b_lunix‘) 261 ern1b = school_bj.grades_list[1] 262 school_sh.creation_grade(‘3n1b_go‘) 263 sann1b = school_sh.grades_list[0] 264 school_bj.creation_grade(‘sinianji‘) #创建一个四年级,为了后边的比对 265 sannianj=school_bj.grades_list[2] 266 # 给三个班级选择老师 267 yin1b.add_course(python) 268 yin1b.add_course(lunix) 269 yin1b.add_teacher(zhanggavin) 270 yin1b.add_teacher(egbert) 271 ern1b.add_course(lunix) 272 ern1b.add_teacher(zhanggavin) 273 ern1b.add_teacher(egbert) 274 sann1b.add_course(go) 275 sann1b.add_teacher(slem) 276 sannianj.add_course(python) 277 # 老师同步班级资料 278 zhanggavin.serch_grade_teacher(yin1b) 279 zhanggavin.serch_grade_teacher(ern1b) 280 egbert.serch_grade_teacher(yin1b) 281 egbert.serch_grade_teacher(ern1b) 282 slem.serch_grade_teacher(sann1b) 283 # 生成几个学生先(self,name,age,sex,stud_id,stud_pwd,money): 284 hanmeimei = Student(‘韩梅梅‘, ‘18‘, ‘w‘, ‘0001‘, ‘1234‘, ‘5000‘) 285 lilei = Student(‘李雷‘, ‘18‘, ‘m‘, ‘0002‘, ‘1234‘, ‘15000‘) 286 wangyuyan = Student(‘王语嫣‘, ‘18‘, ‘w‘, ‘0003‘, ‘1234‘, ‘8000‘) 287 # 注册学校,课程,班级 288 hanmeimei.serch_school_and_enroll(school_bj, hanmeimei) 289 hanmeimei.serch_courese_student(python) 290 hanmeimei.serh_grade_student(hanmeimei,yin1b) #这里不通顺,好气啊 291 lilei.serch_school_and_enroll(school_bj, lilei) 292 lilei.serch_courese_student(python) 293 lilei.serch_courese_student(lunix) 294 lilei.serh_grade_student(lilei,yin1b)#这里不通顺,好气啊 295 lilei.serh_grade_student(lilei,ern1b)#这里不通顺,好气啊 296 wangyuyan.serch_school_and_enroll(school_sh, wangyuyan) 297 wangyuyan.serch_courese_student(go) 298 wangyuyan.serh_grade_student(wangyuyan,sann1b)#这里不通顺,好气啊 299 # 300 # def inupt_grade(a,school,): 301 # global b 302 # for index,i in enumerate(school.grades_name): 303 # if a == i: 304 # a=school.grades_list[index] 305 # # print(a) 306 # # print(a.grade_name) 307 # b=a 308 # # print(a,‘333‘) 309 310 if __name__ == ‘__main__‘: 311 big_flag=False 312 while not big_flag: 313 choose_user = input(‘‘‘ 314 请选择您的角色: 315 1,管理员 316 2,老师 317 3,学生 318 ‘‘‘) 319 if choose_user == ‘1‘: 320 flag = False 321 choose_school = input(‘请选择学校:1,北京学校 2,上海学校 q,按q返回上一层‘) 322 323 if choose_school == ‘1‘: # 这里是个骚操作 324 a = school_bj 325 326 if choose_school == ‘2‘: 327 a = school_sh 328 329 while not flag: 330 print(‘------显示学校信息如下------‘) 331 print(‘现有班级‘, a.grades_name) 332 print(‘现有老师‘, a.teacher_name) 333 print(‘现有课程‘, a.courese_name) 334 print(‘现有学生‘, a.student_name) 335 choose_fun = input(‘请选择功能:1,创建班级 2,创建讲师,3,创建课程 q,按q返回上一层‘) 336 if choose_fun == ‘1‘: 337 inpu_gradename = input(‘班级名称‘) 338 a.creation_grade(inpu_gradename) 339 for index, i in enumerate(a.grades_name): 340 if inpu_gradename == i: 341 inpu_gradename = a.grades_list[index] 342 # inupt_grade(inpu_gradename,school_bj) #执行找班级类的方法 343 # inupt_grade() 344 while not flag: 345 choose_grade_fuc = input(‘班级功能如下:1,班级添加学生 2,班级添加老师 q,按q退回上一界面‘) 346 if choose_grade_fuc == ‘1‘: 347 print(‘可添加的学生列表如下‘) 348 print(a.student_name) 349 ipt_s_g_st = input(‘请选择学生‘) 350 ipt_s_g_st_flage = False 351 for index, i in enumerate(a.student_name): 352 if ipt_s_g_st == i: 353 ipt_s_g_st = a.student_list[index] 354 ipt_s_g_st_flage = True 355 break 356 if ipt_s_g_st_flage is False: 357 print(‘请输入有效的学生名‘) 358 inpu_gradename.add_student(ipt_s_g_st) 359 print(‘当前班级学生列表如下‘) 360 inpu_gradename.tell_student_grade() 361 if choose_grade_fuc == ‘2‘: 362 print(‘可添加的老师列表如下‘) 363 print(a.teacher_name) 364 ipt_s_g_te = input(‘请选择老师‘) 365 ipt_s_g_te_flage = False 366 for index, i in enumerate(a.teacher_name): 367 if ipt_s_g_te == i: 368 ipt_s_g_te = a.teacher_list[index] 369 ipt_s_g_te_flage = True 370 break 371 if ipt_s_g_te_flage is False: #这里多理解一下 372 print(‘请输入有效的老师名‘) 373 inpu_gradename.add_teacher(ipt_s_g_te) # inpu_gradename是个班级实例 374 print(‘当前班级老师列表如下‘) 375 inpu_gradename.teall_teacher_grade() 376 if choose_grade_fuc == ‘q‘: 377 break 378 if choose_fun == ‘2‘: 379 print(‘请输入教师信息‘) 380 ipt_t_name = input(‘姓名‘) 381 ipt_t_age = input(‘年龄‘) 382 ipt_t_sex = input(‘性别‘) 383 ipt_t_courese = input(‘擅长课程‘) 384 course_flag = False 385 for index, i in enumerate(a.courese_name): 386 if ipt_t_courese == i: 387 ipt_t_courese = a.courese_list[index] 388 course_flag = True 389 break 390 if course_flag is False: 391 print(‘你输入的课程不在课程库‘) 392 ipt_t_grade = input(‘分配班级‘) 393 garde_flag = False 394 for index, i in enumerate(a.grades_name): 395 if ipt_t_grade == i: 396 ipt_t_grade = a.grades_list[index] 397 garde_flag = True 398 break 399 if garde_flag is False: 400 print(‘你输入的班级不存在‘) 401 if garde_flag is True: 402 ‘‘‘ 403 这一块相当重要,这里是同步数据的,后边学生模块也能用到类似的 404 ‘‘‘ 405 ipt_t_name = Teacher(ipt_t_name, ipt_t_age, ipt_t_sex) 406 ipt_t_name.serch_courese_teacher(ipt_t_courese) 407 ipt_t_name.serch_grade_teacher(ipt_t_grade) 408 a.creation_techer(ipt_t_name) 409 ipt_t_grade.add_course(ipt_t_courese) 410 ipt_t_grade.add_teacher(ipt_t_name) 411 ipt_t_name.tell() 412 413 if choose_fun == ‘3‘: 414 input_course = input(‘请输入课程名称‘) 415 input_price = input(‘课程价格‘) 416 input_time = input(‘课程周期‘) 417 a.creation_course(input_course, input_price, input_time) 418 for index, i in enumerate(a.courese_name): 419 if input_course == i: 420 input_course = a.courese_list[index] 421 input_course.tell() 422 if choose_fun == ‘q‘: 423 break 424 425 if choose_school == ‘q‘: 426 flag = True 427 428 if choose_user == ‘2‘: 429 teacher_fun_flag=False #以后用的到 430 while not teacher_fun_flag: 431 teacher_name = input(‘请输入姓名以便查找,或者按q返回:::‘) 432 pwd = input(‘请输入密码‘) # 这里假装有个密码 433 teacher_name_flag=False 434 if teacher_name in school_bj.teacher_name and pwd == ‘1234‘: # 这里是个骚操作 435 a = school_bj 436 teacher_name_flag=True 437 if teacher_name in school_sh.teacher_name and pwd == ‘1234‘: 438 a = school_sh 439 teacher_name_flag= True 440 if teacher_name==‘q‘: 441 break 442 if teacher_name_flag is False: 443 print(‘该老师不存在‘) 444 if teacher_name_flag is True: 445 for index, i in enumerate(a.teacher_name): 446 if teacher_name == i: 447 teacher_name = a.teacher_list[index] 448 # teacher_name_school_teacherlist=teacher_name 449 # course_flag = True 450 print(‘登陆成功,信息如下‘) 451 teacher_name.tell() # ‘这里teacher_name 是学校的teacher_list里边的类‘ 452 453 while not teacher_fun_flag: 454 choose_teacher = input(‘请选择功能 1,查看班级信息 2,选择班级上课 3,查看班级学员列表 4,修改所管理的学员成绩 q,返回上一菜单‘) 455 if choose_teacher == ‘1‘: 456 input_gardename_fun1=input(‘请输入要查询的班级名称,名称必须写对‘) 457 jiuyaoli_falg = False 458 for index,i in enumerate(teacher_name.grade_teacher): #这里teacher_name 是个老师类实例 459 if input_gardename_fun1==i: #输入的名称存在老师类实例里的班级列表里 460 jiuyaoli_falg=True 461 break 462 if jiuyaoli_falg is False: 463 print(‘请输入有效的班级名称‘) 464 if jiuyaoli_falg is True: 465 for index,i in enumerate(a.grades_name): #这里a.grades_name 是学校实例的班级名称 466 if input_gardename_fun1==i: 467 input_gardename_fun1=a.grades_list[index] #我怀疑这里变成的学校里边班级列表里的班级实例了 因为只有学校列表里有班级实例 468 # print(input_gardename_fun2.teacher_grade_name) 469 # print(input_gardename_fun2.student_grade_name) 470 # print(input_gardename_fun2) 471 # print(input_gardename_fun2.teacher_grade_name,‘老师名字‘) 472 # print(input_gardename_fun2.teacher_grade,‘这个是teachergrade里边放着类‘) 473 # print(input_gardename_fun2.student_grade,‘这应该是类才对‘) 474 # print(input_gardename_fun2.student_grade_name,‘学生名字‘) 475 print(‘-----%s学生列表-----‘%input_gardename_fun1.grade_name) #这里调用班级实例的方法 476 input_gardename_fun1.tell_student_grade() 477 print(‘-----%s老师列表-----‘ % input_gardename_fun1.grade_name) 478 input_gardename_fun1.teall_teacher_grade() 479 print(‘-----%s课程内容-----‘ % input_gardename_fun1.grade_name) 480 print(input_gardename_fun1.courese_type) 481 482 if choose_teacher == ‘2‘: 483 teacher_name.check_grades() 484 # teacher_name.check_student_grade_student() 485 input_gardename_fun2=input(‘输入上课的班级名称‘) 486 inpu_fun_falg_111 = False 487 for i in teacher_name.grade_teacher: 488 if input_gardename_fun2==i: 489 print(i) 490 input_course_fun2 = input(‘请输入课程‘) 491 for i in teacher_name.courese_teacher: 492 if input_course_fun2==i: 493 inpu_fun_falg_111 = True 494 if inpu_fun_falg_111 is False: 495 print(‘请输入正确的班级名称‘) 496 if inpu_fun_falg_111 is True: 497 a=print(‘%s在%s班,上%s课程‘%(teacher_name.name,input_gardename_fun2,input_course_fun2)) 498 log(a) 499 # 500 # inpu_fun_falg_111=False 501 # inpu_fun_falg_222=False 502 # for index,i in enumerate(teacher_name.grade_teacher): #这里的teacher_name 还是老师的实例类(in school).grade_teacher就是实例类里的班级列表 503 # if input_gardename_fun2 == i: # 504 # input_gardename_fun2 = a.grades_list[index] #这里变成了班级实例类 505 # print(input_gardename_fun2.grades_name,‘看看这是什么‘) 506 # inpu_fun_falg_111 = True 507 # break 508 # if inpu_fun_falg_111 is False: 509 # print(‘你输入的班级不存在‘) 510 # if inpu_fun_falg_111 is True: 511 # print(input_gardename_fun2.grade_name, ‘kan ,mingzi 这里变成了类‘) 512 # for index, i in enumerate(teacher_name.courese_teacher): 513 # if input_course_fun2 == i: 514 # input_course_fun2 = a.courese_list[index] #这里变成了课程实例类 515 # print(input_course_fun2.type, ‘这里应该是个类‘) 516 # inpu_fun_falg_222 = True 517 # flag = False 518 # if inpu_fun_falg_222 is False: 519 # print(‘你输入的课程不存在‘) 520 # if inpu_fun_falg_222 is True: 521 # # print(input_gardename_fun2.courese_type,‘班级的课程列表‘) 522 # teacher_name.teaching(teacher_name,teacher_name) 523 if choose_teacher==‘3‘: 524 teacher_name.check_grades() 525 print(‘将查询%s名下所有班级的成员‘%teacher_name.grade_teacher) 526 #将查询[‘1n1b_python‘, ‘2n1b_lunix‘]名下所有班级的成员 527 # print(a.grades_name,‘eee‘) 528 #[‘1n1b_python‘, ‘2n1b_lunix‘, ‘sinianji‘] eee 529 # for index,i in enumerate(a.grades_name): 530 # if i==a.grades_name[index]: 531 # i=a.grades_list[index] 532 # print(teacher_name.grade_teacher[index]) 533 # print(i.student_grade_name) 534 wusong_flag=False 535 list_i = [] 536 for i in teacher_name.grade_teacher: 537 for index,j in enumerate(a.grades_name): 538 if i ==j: 539 i= a.grades_list[index] 540 list_i.append(i) 541 wusong_flag=True 542 if wusong_flag is False: 543 print(‘名下没学生‘) 544 if wusong_flag is True: 545 # print(list_i,‘3333‘) 546 # print(list_i[0].grade_name,‘4444‘) #这里是学校里的班级类实力? 547 for index,i in enumerate(list_i): 548 print(i.grade_name) 549 print(i.student_grade_name) 550 # print(teacher_name.grade_teacher[index]) 551 # print(i.student_grade_name) 552 # inpu_fun_falg_111 = False 553 # for i in teacher_name.grade_teacher: 554 # if input_gardename_fun2 == i: 555 # print(i) 556 # input_course_fun2 = input(‘请输入课程‘) 557 # for i in teacher_name.courese_teacher: 558 # if input_course_fun2 == i: 559 # inpu_fun_falg_111 = True 560 # if inpu_fun_falg_111 is False: 561 # print(‘请输入正确的班级名称‘) 562 # if inpu_fun_falg_111 is True: 563 # a = print(‘%s在%s班,上%s课程‘ % (teacher_name.name, input_gardename_fun2, input_course_fun2)) 564 # log(a) 565 if choose_teacher==‘4‘: 566 print(‘修改你MB,啥玩意没有改啥‘) 567 568 if choose_teacher==‘q‘: 569 break 570 if choose_user == ‘3‘: 571 stu_falg=False 572 while not stu_falg: 573 print(‘欢迎学习‘) 574 print(‘请先注册你的信息‘) 575 name_stu=input(‘请输入你的名字‘) 576 age_stu=input(‘请输入你的年龄‘) 577 sex_stu=input(‘请输入性别‘) 578 stuid_stu=input(‘请输入一个你喜欢的学生编号,反正没用‘) 579 pwd_stu=input(‘密码请输入1234‘) 580 money_stu=input(‘请玩命充钱,谢谢‘) 581 stu_class = Student(name_stu,age_stu,sex_stu,stuid_stu,pwd_stu,money_stu) #这里是实类 582 print(‘根据学校信息选择适合你的学校‘) 583 print(‘-----1,北方-----‘) 584 school_bj.tell_school() 585 print(‘-----2,南方-----‘) 586 school_sh.tell_school() 587 zhuce_flag=False 588 choose_stu=input(‘请选择学校名称的编号‘) 589 590 if choose_stu ==‘1‘: # 这里是个骚操作 591 a = school_bj 592 593 if choose_stu ==‘2‘: 594 a = school_sh 595 596 597 stu_class.serch_school_and_enroll(a,stu_class) 598 zhuce_flag=True 599 600 if zhuce_flag is True: 601 print(‘课程内容如下‘,a.courese_name) 602 choose_stu_course=input(‘请选择课程‘) 603 xuanzekecheng_falg=False 604 for index,i in enumerate(a.courese_name): 605 if choose_stu_course==i: 606 choose_stu_course=a.courese_list[index] 607 #print(choose_stu_course,‘应该是个类,应该是学校列表里边的coures实例‘) 608 print(‘你选择的课程信息如下‘) 609 print(‘课程名称:%s\n价格:%s\n周期:%s\n‘%(choose_stu_course.type,choose_stu_course.price,choose_stu_course.time)) 610 yesorno=input(‘请选择yes or no‘) 611 if yesorno==‘yes‘: 612 xuanzekecheng_falg=True 613 break 614 if yesorno==‘no‘: 615 print(‘知识无价,还请好好考虑‘) 616 xuanzekecheng_falg=False 617 break 618 else: 619 print(‘你输入的信息不正确,我当你不同意处理‘) 620 xuanzekecheng_falg = False 621 break 622 # if xuanzekecheng_falg is False: 623 # print(‘失败了???????????????????????‘) 624 # break 625 jiagepanduan_flag = False 626 if xuanzekecheng_falg is True: 627 # print(stu_class.money) 628 # print(type(stu_class.money)) 629 # print(choose_stu_course.price) 630 # print(type(choose_stu_course.price)) 631 if float(stu_class.money) > float(choose_stu_course.price): 632 stu_class.serch_courese_student(choose_stu_course) 633 stu_class.pay_courese_price(choose_stu_course) 634 jiagepanduan_flag =True 635 else: 636 print(‘请继续充钱‘) 637 if jiagepanduan_flag is True: 638 print(‘钱都花了,选个班吧‘) 639 suibian_name_list=[] 640 suibian_calss_list=[] 641 kecheng_name=choose_stu_course.type #提取课程名称 642 for index,i in enumerate(a.grades_list): 643 # print(i.grade_name,‘这里应该是班级类的name‘) 644 # 1n1b_python 这里应该是类的name 645 for j in i.courese_type: #在班级的课程列表里循环 646 if kecheng_name==j: 647 # print(i.grade_name,‘这里应该打印含有该课程的班级‘) 648 suibian_name_list.append(i.grade_name) 649 suibian_calss_list.append(i) 650 print(‘有以下班级开展%s‘%choose_stu_course.type) 651 print(suibian_name_list) 652 choose_grade_stu=input(‘选择班级‘) 653 for index,i in enumerate(a.grades_name): 654 if choose_grade_stu == i : 655 choose_grade_stu = a.grades_list[index] 656 stu_class.serh_grade_student(stu_class,choose_grade_stu) 657 print(‘胜利!‘) 658 659 660 661 # def serh_grade_student(self, obj_student, obj_grade): # 这里我改了一下,这里不通顺 662 # print(‘录入班级%s‘ % obj_grade.grade_name) 663 # obj_grade.student_grade_name.append(self.name) # 添加班级名字到班级类文件夹$$$$$$$$$$$$$$$$$$$$$$$ 664 # obj_grade.student_grade.append(obj_student) # 添加实类到班级,好像没大有用 665 # self.grade_class_student.append(obj_grade.grade_name) 666 # print(‘班级%s选择成功,已将班级信息添加到班级类,学生类‘ % obj_grade.grade_name) 667 668 # for index,i in enumerate(a.courese_name): 669 # if choose_stu_course==i: 670 # choose_stu_course=a.courese_list[index] 671 # #print(choose_stu_course,‘应该是个类,应该是学校列表里边的coures实例‘) 672 # print(‘你选择的课程信息如下‘) 673 # print(‘课程名称:%s\n价格:%s\n周期:%s\n‘%(choose_stu_course.type,choose_stu_course.price,choose_stu_course.time)) 674 675 676 677 # list_i = [] 678 # for i in teacher_name.grade_teacher: 679 # for index, j in enumerate(a.grades_name): 680 # if i == j: 681 # i = a.grades_list[index] 682 # list_i.append(i) 683 # # print(list_i,‘3333‘) 684 # # print(list_i[0].grade_name,‘4444‘) #这里是学校里的班级类实力? 685 # for index, i in enumerate(list_i): 686 # print(i.grade_name) 687 # print(i.student_grade_name) 688 689 690 # print(‘北方学校的课程如下‘) 691 # print(school_bj.courese_name) def serh_grade_student(self, obj_student,obj_grade): 692 # stu_courese=input(‘请选择课程名称‘) 693 # for index ,i in school_bj.courese_name: #这里不着急,一会再屡屡 694 # if stu_courese==i: 695 # stu_courese=school_bjdadad 696 697 698 699 700 if choose_user==‘q‘: 701 break 702 703 704 705 706 707 708 # if choose_teacher == ‘1‘: 709 # print(a.grades_name) 710 # for index, i in enumerate(a.grades_name): 711 # print(a.grades_name[index]) 712 # print(i,‘i‘) 713 # for index,i in enumerate(a.grades_name) 714 # 715 716 717 # for index, i in enumeratddadadadaddade(a.grades_name): 718 # if b == i: 719 # b = a.grades_list[index] 720 # # ipt_s_g_te_flage = True 721 # if teacher_name i
运行效果
原文地址:https://www.cnblogs.com/PYlog/p/9039822.html
时间: 2024-10-12 08:55:06