作业需求:

角色:学校、学员、课程、讲师、完成下面的要求

1. 创建北京、上海 2 所学校

2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开

3. 课程包含,周期,价格,通过学校创建课程

4. 通过学校创建班级, 班级关联课程、讲师

5. 创建学员时,选择学校,关联班级

5. 创建讲师角色时要关联学校,

6. 提供两个角色接口

6.1 学员视图, 可以注册, 交学费, 选择班级,

6.2 讲师视图, 讲师可管理自己的班级, 上课时选择班级, 查看班级学员列表 , 修改所管理的学员的成绩

6.3 管理视图,创建讲师, 创建班级,创建课程

7. 上面的操作产生的数据都通过pickle序列化保存到文件里

思路(简单整理)

关联关系:

1.学校-班级

2. 班级-课程-讲师

3.讲师-学校

4.学生-学校-班级-(这里隐藏了一个关联关系就是班级还关联这-课程-讲师)

分析后得出5个类,学校,课程,班级,讲师,学生,创建这5个类,然后用学校类将关联关系理清,然后用三个视图调用不同对象进行操作。

简单流程图:

README:

  1. 作者:yaobin
  2. 版本:示例版本 v0.1 mmp版本 :(
  3. 程序介绍:
  4.  
  5. 1. 创建北京、上海 2 所学校
  6. 2. 创建linux , python , go 3个课程 linux\py 在北京开, go 在上海开
  7. 3. 课程包含,周期,价格,通过学校创建课程
  8. 4. 通过学校创建班级, 班级关联课程、讲师
  9. 5. 创建学员时,选择学校,关联班级
  10. 5. 创建讲师角色时要关联学校,
  11. 6. 提供两个角色接口
  12. 6.1 学员视图, 可以注册, 交学费, 选择班级,
  13. 6.2 讲师视图, 讲师可管理自己的班级, 上课时选择班级, 查看班级学员列表 修改所管理的学员的成绩
  14. 6.3 管理视图,创建讲师, 创建班级,创建课程
  15. 7. 上面的操作产生的数据都通过pickle序列化保存到文件里
  16.  
  17. 文件目录
  18.  
  19. ---选课系统 #主程序目录
  20. README
  21. __init__.py

  22. ├─bin
  23. Course_Selecting.py #主程序
  24. __init__.py

  25. ├─conf
  26. setting.py #配置文件
  27. __init__.py

  28. ├─core
  29. main.py #主逻辑交互程序
  30. school_view.py #学校视图
  31. student_view.py #学生视图
  32. teacher_view.py #老师视图
  33. __init__.py

  34. ├─db
  35. 1.py
  36. school.bak
  37. school.dat #数据db
  38. school.dir

  39. ├─logs
  40. __init__.py

  41. ├─src
  42. class_classroom.py #教室类
  43. class_course.py #课程类
  44. class_school.py #学校类
  45. class_student.py #学生类
  46. class_teacher.py #老师类
  47. __init__.py

  48. └─test
  49. __init__.py

代码部分:

bin / Course_Selecting.py 

  1. #!/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3. # Author: Colin Yao
  4. import os,sys,logging,shelve
  5. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  6. sys.path.append(BASE_DIR) #添加环境变量
  7. from conf import setting
  8. from core.main import Admin
  9.  
  10. if __name__ == '__main__':
  11. Admin.run('')

conf / setting.py

  1. #!/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3. # Author: Colin Yao
  4. import os,time,shelve,sys
  5. from src.class_school import School
  6. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  7. sys.path.append(BASE_DIR) #添加环境变量
  8. data_path = os.path.join(BASE_DIR+'\db')
  9. school_file = os.path.join(data_path,'school')

core / main.py

  1. #!/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3. # Author: Colin Yao
  4. import os,sys,logging,shelve
  5. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  6. sys.path.append(BASE_DIR) #添加环境变量
  7. from conf import setting
  8. from core.school_view import School_view
  9. from core.teacher_view import Teacher_view
  10. from core.student_view import Student_view
  11.  
  12. class Admin(object):
  13. def run(self):
  14. exit_flag =False
  15. menu = u'''
  16. \033[32;1m
  17. 1.学生视图
  18. 2.老师视图
  19. 3.学校视图
  20. 4.退出\033[0m
  21. '''
  22. while not exit_flag:
  23. print(menu)
  24. user_option = input('请输入要管理的视图,输入q退出>>>:\t')
  25. if user_option == '':
  26. Student_view()
  27. elif user_option == '':
  28. Teacher_view()
  29. elif user_option == '':
  30. School_view()
  31. elif user_option == 'q' or user_option =='':
  32. sys.exit()
  33. else:
  34. print('输入的选项不正确,请重新输入')

  school_view.py

  1. #!/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3. # Author: Colin Yao
  4. import os,sys,logging,shelve
  5. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  6. sys.path.append(BASE_DIR) #添加环境变量
  7. from conf import setting
  8. from src.class_school import School
  9.  
  10. class School_view(object):
  11. def __init__(self):
  12. if os.path.exists(setting.school_file+ '.dat'):
  13. self.school_file = shelve.open(setting.school_file)
  14. self.school_manger()
  15. self.school_file.close()
  16. else:
  17. print('没有学校和班级的数据,请先创建')
  18. self.init_school()
  19. self.school_manger()
  20. self.school_file.close()
  21. def init_school(self):
  22. self.school_file = shelve.open(setting.school_file)
  23. self.school_file['北京'] = School('总校','北京')
  24. self.school_file['上海'] = School('总校','上海')
  25.  
  26. def school_manger(self):
  27. while True:
  28. for school_name in self.school_file:
  29. print('学校名称:%s'%school_name)
  30. school_option = input('请输入要管理的学校名称>>>:').strip()
  31. if school_option in self.school_file:
  32. self.school_option = school_option
  33. self.school_obj = self.school_file[school_option]
  34. '''
  35. 如果是北京就等于self.school_obj[北京]
  36. file[北京] =School('总校','北京')
  37. 所以当下文出现了self.school_obj.school_course =School('总校','北京').school_course
  38. 等同于调用了School().school_course的属性是
  39. '''
  40. while True:
  41. menu = '''
  42. 欢迎来到 Python%s校区
  43. 添加课程 add_course
  44. 添加班级 add_classroom
  45. 添加讲师 add_teacher
  46. 查看班级 show_classroom
  47. 查看课程 show_classroom
  48. 查看讲师 show_teacher
  49. 修改讲师 add_teacher
  50. 退出 exit
  51. '''%school_option
  52. print(menu)
  53. user_choice = input('请选择以上操作>>>:').strip()
  54. if hasattr(self,user_choice):
  55. getattr(self,user_choice)()
  56. else:
  57. print("没有这个操作,请重新输入!!!!")
  58. pass
  59.  
  60. def add_course(self):
  61. course_name = input('请输入课程名称>>>:').strip()
  62. course_price = input('请输入课程价格>>>:').strip()
  63. course_time = input('请输入课程周期[默认为周]>>>:').strip()
  64. if course_name in self.school_obj.school_course:
  65. print('课程已经存在')
  66. else:
  67. self.school_obj.create_course(course_name, course_price, course_time) #相当于School.create_course(course_name, course_price, course_time)
  68. print('%s课程添加成功' % course_name)
  69. self.school_file.update({self.school_option:self.school_obj})
  70. self.school_file.close()
  71.  
  72. def add_classroom(self):
  73. class_name = input('请输入班级名称>>>:').strip()
  74. class_course = input('请输入课程>>>:').strip()
  75. if class_name not in self.school_obj.sch_class_room: #sch_class_room
  76. if class_name not in self.school_obj.school_course:
  77. course_obj = self.school_obj.school_course[class_course]
  78. self.school_obj.create_classroom(class_name,course_obj)
  79. self.school_file.update({self.school_option:self.school_obj})
  80. self.school_file.close()
  81. print('班级创建成功')
  82. else:
  83. print('课程不存在')
  84. else:
  85. print('班级已经存在')
  86.  
  87. def show_classroom(self):
  88. for classroom in self.school_obj.sch_class_room:
  89. class_obj = self.school_obj.sch_class_room[classroom]
  90. print('班级名称:%s\t课程:%s'
  91. % (class_obj.class_name,class_obj.course_obj.course_name))
  92.  
  93. def add_teacher(self):
  94. teacher_name = input('请输入讲师姓名>>>:')
  95. teacher_age = input('请输入讲师年龄>>>:')
  96. teacher_gender = input('请输入讲师性别>>>:')
  97. teacher_salary = input('请输入讲师薪水>>>:')
  98. class_name = input('请输入授课班级>>>:')
  99.  
  100. if class_name in self.school_obj.sch_class_room: # sch_class_room
  101. class_obj = self.school_obj.sch_class_room[class_name]
  102. if teacher_name not in self.school_obj.sch_teacher:
  103. self.school_obj.create_teacher(teacher_name,teacher_age,teacher_gender,teacher_salary,class_name,class_obj)
  104. print('讲师创建成功,请确认是否已经签完合同')
  105. else:
  106. self.school_obj.modify_teacher({})
  107. print('修改讲师成功')
  108. self.school_file.update({self.school_option:self.school_obj})
  109. self.school_file.close()
  110. else:
  111. print('请先创建班级')
  112.  
  113. def show_teacher(self):
  114. for teacher_name in self.school_obj.sch_teacher:
  115. teacher_obj = self.school_obj.sch_teacher[teacher_name]
  116. for t in teacher_obj.teacher_classroom:
  117. class_obj = self.school_obj.sch_class_room[t]
  118. stu_list = []
  119. for j in class_obj.class_student:
  120. stu_list.append(j)
  121. print('教师姓名:%s\t教师所在班级:%s\t教授课程:%s\t课程学员:%s' %(teacher_obj.teacher_name
  122. ,t,class_obj.course_obj.course_name,class_obj.class_student))
  123.  
  124. def exit(self):
  125. sys.exit('程序退出')

  student_view.py

  1. #!/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3. # Author: Colin Yao
  4. import os, sys, logging, shelve
  5.  
  6. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  7. sys.path.append(BASE_DIR) # 添加环境变量
  8. from conf import setting
  9. from src.class_school import School
  10. from core.school_view import School_view
  11.  
  12. class Student_view(object):
  13. def __init__(self):
  14. if os.path.exists(setting.school_file+ '.dat'):
  15. self.school_file = shelve.open(setting.school_file)
  16. self.student_manger()
  17. self.school_file.close()
  18. else:
  19. print('没有数据,请联系管理员选择分校')
  20. sys.exit()
  21. def student_manger(self):
  22. while True:
  23. print('欢迎注册IT学院我们的分校有:')
  24. for school_name in self.school_file:
  25. print('\tSean[%s]分校' %school_name)
  26. school_option = input('请输入您要学习的分校地址>>>:').strip()
  27.  
  28. if school_option in self.school_file:
  29. self.school_option = school_option
  30. self.school_obj = self.school_file[school_option]
  31. else:
  32. print('输入有误程序退出')
  33. sys.exit()
  34. for classroom in self.school_obj.sch_class_room:
  35. class_obj = self.school_obj.sch_class_room[classroom]
  36. print('欢迎来到%s分校我们的班级有:%s\t课程有:%s'
  37. % (school_option, class_obj.class_name, class_obj.course_obj.course_name))
  38.  
  39. student_option = input('请输入学生姓名进行操作[PS:注册也在这里哟]>>>:').strip()
  40. if student_option in self.school_obj.sch_student:
  41. self.student_option = student_option
  42. self.student_obj = self.school_obj.sch_student[self.student_option]
  43. else:
  44. print('[%s]这位童鞋'%student_option,'您是否进行注册?')
  45. user_choice = input('请注册/退出(y/n)>>>:')
  46. if user_choice == 'y':
  47. self.student_option = student_option
  48. self.enroll()
  49. elif user_choice == 'n':
  50. sys.exit()
  51. else:
  52. print('输入有误,请重新开始 = 。= ')
  53. self.student_manger()
  54. while True:
  55. menu = '''
  56. 欢迎来到 Python[%s]校区[%s]童鞋
  57. 缴纳学费 pay
  58. 选择教室/课程 choice_class
  59. 查看讲师 view_teacher
  60. 退出 exit
  61. ''' %(school_option,student_option)
  62. print(menu)
  63. user_choice = input('请选择以上操作>>>:').strip()
  64. if hasattr(self, user_choice):
  65. getattr(self, user_choice)()
  66. else:
  67. print("没有这个操作,请重新输入!!!!")
  68. pass
  69.  
  70. '''注册'''
  71. def enroll(self): # 课程、班级
  72. student_name = self.student_option
  73. student_gender = input('%s童鞋请输入性别>>>:' % student_name)
  74. student_age = input('%s童鞋请输入年纪>>>:' % student_name)
  75. class_name = input('%s童鞋请输入教室(PS:教室已经和课程关联)>>>:' % student_name)
  76. student_score = None
  77. if class_name in self.school_obj.sch_class_room:
  78. class_obj = self.school_obj.sch_class_room[class_name]
  79. self.school_obj.create_student(student_name, student_gender, student_age, student_score, class_name)
  80. self.school_file.update({self.school_option: self.school_obj})
  81. self.school_file.close()
  82. print('%s童鞋注册成功,您选择的课程是%s,教室为%s'
  83. % (student_name, class_obj.course_obj.course_name, class_obj.class_name))
  84. else:
  85. print('创建失败教室不存在')
  86.  
  87. '''缴纳学费'''
  88.  
  89. def pay(self): # 根据教室缴纳学费
  90. student_name = self.student_option
  91. class_name = input('%s童鞋请输入您所在的教室(PS:教室已经和课程关联)>>>:' % student_name)
  92. if class_name in self.school_obj.sch_class_room: # sch_class_room
  93. class_obj = self.school_obj.sch_class_room[class_name]
  94. if class_obj.course_obj.course_name in self.school_obj.school_course:
  95. course_obj = self.school_obj.school_course[class_obj.course_obj.course_name]
  96. print('所在分校:%s\t课程名称:%s\t课程价格:%s\t课程学习计划:%s周'
  97. % (self.school_obj.school_addr, course_obj.course_name, course_obj.course_price, course_obj.course_time))
  98.  
  99. '''选择班级'''
  100. def choice_class(self): # 根据学习日期选择班级
  101. student_name = self.student_option
  102. student_gender = self.student_obj.student_gender
  103. student_age = self.student_obj.student_age
  104. class_name = input('%s童鞋选择教室(PS:教室已经和课程关联)>>>:' % student_name)
  105. student_score = 0
  106. # class_name ='room'
  107. if class_name in self.school_obj.sch_class_room: # sch_class_room
  108. class_obj = self.school_obj.sch_class_room[class_name]
  109. self.school_obj.create_student(student_name, student_gender, student_age, student_score, class_name)
  110. self.school_file.update({self.school_option: self.school_obj})
  111. self.school_file.close()
  112. print('%s更改教室成功,您选择的课程是%s,教室为%s'
  113. % (student_name, class_obj.course_obj.course_name, class_obj.class_name))
  114. else:
  115. print('创建失败教室不存在')
  116.  
  117. '''查看讲师'''
  118. def view_teacher(self):
  119. for teacher_name in self.school_obj.sch_teacher:
  120. teacher_obj = self.school_obj.sch_teacher[teacher_name]
  121. for t in teacher_obj.teacher_classroom:
  122. class_obj = self.school_obj.sch_class_room[t]
  123. stu_list = []
  124. for j in class_obj.class_student:
  125. stu_list.append(j)
  126. print('教师姓名:%s\t教师所在班级:%s\t教授课程:%s\t学生有%s'
  127. % (teacher_obj.teacher_name,t, class_obj.course_obj.course_name,stu_list))
  128. '''退出'''
  129. def exit(self):
  130. sys.exit('感谢使用再见')

  teacher_view.py

  1. #!/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3. # Author: Colin Yao
  4. import os,sys,logging,shelve
  5. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  6. sys.path.append(BASE_DIR) #添加环境变量
  7. from conf import setting
  8. from src.class_school import School
  9.  
  10. class Teacher_view(object):
  11. def __init__(self):
  12. if os.path.exists(setting.school_file+ '.dat'):
  13. self.school_file = shelve.open(setting.school_file)
  14. self.teacher_manger()
  15. self.school_file.close()
  16. else:
  17. print('没有教师数据,请先创建学校')
  18. sys.exit()
  19. def teacher_manger(self):
  20. while True:
  21. print('欢迎进入IT学院讲师视图:')
  22. for school_name in self.school_file:
  23. print('讲师分校名:%s' % school_name)
  24. school_option = input('请输入您所在分校名>>>:').strip()
  25. if school_option in self.school_file:
  26. self.school_option = school_option
  27. self.school_obj = self.school_file[school_option]
  28. else:
  29. print('您的输入有误')
  30. break
  31. teacher_option = input('请输入讲师姓名进行管理>>>:').strip()
  32. if teacher_option in self.school_obj.sch_teacher:
  33. self.teacher_option = teacher_option
  34. self.teacher_obj = self.school_obj.sch_teacher[self.teacher_option]
  35. print('欢迎讲师%s进入讲师管理系统以下是您的讲师信息:'
  36. '\n讲师姓名:%s\t讲师年龄:%s\t讲师性别:%s\t讲师工资:%s'
  37. %(self.teacher_obj.teacher_name,self.teacher_obj.teacher_name
  38. ,self.teacher_obj.teacher_age,self.teacher_obj.teacher_gender,self.teacher_obj.teacher_salary))
  39. else:
  40. print('没有[%s]这位讲师'%teacher_option)
  41. sys.exit()
  42. while True:
  43. menu = '''
  44. 欢迎来到 Python[%s]校区[%s]讲师
  45. 选择教室 management_class
  46. 查看班级 view_class
  47. 查看学员 view_student_list
  48. 修改成绩 revise_student_grades
  49. 退出 exit
  50. ''' %(school_option,teacher_option)
  51. print(menu)
  52. user_choice = input('请选择以上操作>>>:').strip()
  53. if hasattr(self, user_choice):
  54. getattr(self, user_choice)()
  55. else:
  56. print("没有这个操作,请重新输入!!!!")
  57. pass
  58.  
  59. '''管理自己的班级'''
  60. def management_class(self):
  61. for classroom in self.teacher_obj.teacher_classroom:
  62. class_obj = self.teacher_obj.teacher_classroom[classroom] #教室对象
  63. print('%s您所在的班级为:%s\t教授的课程是%s:' % (self.teacher_obj.teacher_name,
  64. class_obj.class_name,class_obj.course_obj.course_name)) # 讲师对应教室和课程
  65. user_choice = input('是否选择要上课的教室y/n>>>:').strip()
  66. if user_choice == 'y':
  67. class_name = input('请输入要上课的教室>>>:').strip()
  68. class_obj = self.school_obj.sch_class_room[class_name]
  69. self.school_obj.create_teacher(self.teacher_obj.teacher_name, self.teacher_obj.teacher_age,
  70. self.teacher_obj.teacher_gender,self.teacher_obj.teacher_salary,class_name,
  71. class_obj)
  72. print('讲师选择教室对应的课程成功')
  73. self.school_file.update({self.school_option:self.school_obj})
  74. self.school_file.close()
  75. elif user_choice == 'n':
  76. print('不对班级进行管理....请重新选择您的操作!!!>>>:')
  77. pass
  78. else:
  79. print('输入不正确')
  80. pass
  81.  
  82. '''上课选择班级和管理班级'''
  83. def view_class(self): # 上课选择班级,
  84. for classroom in self.teacher_obj.teacher_classroom:
  85. class_obj = self.teacher_obj.teacher_classroom[classroom] # 教室对象
  86. print('%s您所在的班级为:%s\t教授的课程是%s:' % (self.teacher_obj.teacher_name,
  87. class_obj.class_name, class_obj.course_obj.course_name)) # 讲师对应教室和课程
  88.  
  89. '''查看学员列表'''
  90. def view_student_list(self): # 查看学员列表
  91. for classroom in self.teacher_obj.teacher_classroom:
  92. class_obj = self.teacher_obj.teacher_classroom[classroom] # 教室对象
  93. stu_list = []
  94. for j in class_obj.class_student:
  95. stu_list.append(j)
  96. print('%s您所在的班级为:%s\t教授的课程是%s\t您班级里的学生有%s:' % (self.teacher_obj.teacher_name,
  97. class_obj.class_name, class_obj.course_obj.course_name,
  98. stu_list)) # 讲师对应教室和课程有问题
  99. '''修改成绩'''
  100. def revise_student_grades(self):
  101. self.view_student_list()
  102. for classroom in self.teacher_obj.teacher_classroom:
  103. class_obj = self.school_obj.sch_class_room[classroom] # 教室对象
  104. student_name = input('请讲师修改成绩的学生的姓名>>>:').strip()
  105. if student_name in class_obj.class_student:
  106. student_obj = class_obj.class_student[student_name]
  107. print('%s童鞋成绩为%s\t课程:%s\t教室:%s'
  108. %(student_name, student_obj.student_score, class_obj.course_obj.course_name, class_obj.class_name))
  109. student_gender = student_obj.student_gender
  110. student_age = student_obj.student_age
  111. new_score = input('请讲师修改成绩>>>:').strip()
  112. self.school_obj.create_student\
  113. (student_name, student_gender, student_age, new_score,class_obj.class_name)
  114. self.school_file.update({self.school_option: self.school_obj})
  115. self.school_file.close()
  116. print('%s童鞋修改成功,他的成绩为%s,他的课程是%s,教室为%s'
  117. % (student_name, new_score, class_obj.class_name, class_obj.course_obj.course_name))
  118. else:
  119. print('没有这个童鞋>>>>>!!!!')
  120.  
  121. def exit(self):
  122. sys.exit('[%s]讲师感谢使用再见'%self.teacher_obj.teacher_name)

db

logs

src / class_classroom.py

  1. #!/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3. # Author: Colin Yao
  4. import time
  5. '''班级类'''
  6. class Class_room(object):
  7. def __init__(self,class_name,course_obj):
  8. self.class_name = class_name
  9. self.course_obj = course_obj
  10. self.class_student = {}

  class_course.py

  1. #!/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3. # Author: Colin Yao
  4. '''课程类'''
  5. import time
  6. class Course(object):
  7. def __init__(self,course_name,course_price,course_time):
  8. self.course_name = course_name
  9. self.course_price = course_price
  10. self.course_time = course_time

  class_school.py

  1. #!/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3. # Author: Colin Yao
  4. import time,os,shelve,sys
  5. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  6. sys.path.append(BASE_DIR) #添加环境变量
  7. from src.class_teacher import Teacher
  8. from src.class_course import Course
  9. from src.class_classroom import Class_room
  10. from src.class_student import Student
  11. '''学校类'''
  12. class School(object):
  13. def __init__(self,school_name,school_addr):
  14. self.school_name = school_name
  15. self.school_addr = school_addr
  16. self.school_course = {}
  17. self.sch_class_room ={}
  18. self.sch_teacher = {}
  19. self.sch_student = {}
  20.  
  21. '''创建课程'''
  22. def create_course(self,course_name,course_price,course_time):
  23. course_obj = Course(course_name,course_price,course_time) #创建课程对象
  24. self.school_course[course_name] = course_obj #根据课程名为key,课程对象为value创建对应关系传进了init self.school_course
  25.  
  26. '''展示课程'''
  27. def show_course(self):
  28. for course in self.school_course:
  29. course_obj = self.school_course[course]
  30. print(course_obj.__dict__) #是否需要添加学校
  31. print('所在分校:%s\t课程名称:%s\t课程价格:%s\t课程学习计划:%s周'
  32. %(self.school_addr,course_obj.course_name,course_obj.course_price,course_obj.course_time))
  33.  
  34. '''修改课程'''
  35. def modify_course(self): #可能会继续追加、保留
  36. for course in self.school_course:
  37. course_obj = self.school_course[course]
  38. course_obj.course_name= input('修改课程名称>>>:')
  39. course_obj.course_price = input('修改课程价格>>>:')
  40. course_obj.course_time = input('修改课程周期>>>:')
  41.  
  42. '''创建教室'''
  43. def create_classroom(self,class_name,course_obj): #创建classroom、关联课程
  44. class_obj = Class_room(class_name,course_obj) #创建课程对象
  45. self.sch_class_room[class_name] = class_obj #根据教室名为key,课程对象为value创建对应关系传进了init self.school_course
  46.  
  47. '''展示教室'''
  48. def show_classroom(self):
  49. for classroom in self.sch_class_room:
  50. class_obj = self.sch_class_room[classroom]
  51. #应该是班级名称、对应课程、对应老师、对应的student、保留
  52. print('班级名称:%s\t课程:%s'
  53. % (class_obj.class_name,class_obj.course_obj))
  54. print(class_obj.__dict__)
  55.  
  56. '''修改教室'''
  57. def modify_course(self): #可能会继续追加、保留
  58. for classroom in self.sch_class_room:
  59. class_obj = self.sch_class_room[classroom]
  60. x = time.strftime("%Y%m%d%H%M%S", time.localtime()) #按照根据时间修改教室省去输入
  61. class_obj.course_obj = input('请慎重输入课程名称>>>:')
  62. y = time.strftime("%Y%m%d%H%M%S", time.localtime())
  63. class_obj.class_name= (y+"_"+ class_obj.course_obj)
  64.  
  65. '''创建教师'''
  66. def create_teacher(self,teacher_name,teacher_age,teacher_gender,teacher_salary,class_name,class_obj):
  67. teacher_obj = Teacher(teacher_name,teacher_age,teacher_gender,teacher_salary)
  68. teacher_obj.add_tech_classroom(class_name,class_obj) #讲师关联教室
  69. self.sch_teacher[teacher_name] = teacher_obj
  70.  
  71. '''查看教师'''
  72. def show_teacher(self):
  73. for teacher_name in self.teacher:
  74. teacher_obj=self.teacher[teacher_name]
  75. print('老师姓名:%s','老师年龄:%s','老师性别:%s','老师工资:%s'
  76. %(teacher_obj.teacher_name,teacher_obj.teacher_age,teacher_obj.teacher_gender,teacher_obj.teacher_salary))
  77.  
  78. '''修改老师'''
  79. def modify_teacher(self):
  80. for teacher_name in self.teacher:
  81. teacher_obj=self.teacher[teacher_name]
  82. teacher_obj.teacher_name = input('请输入修改的老师姓名>>>:')
  83. teacher_obj.teacher_age = input('请输入修改的老师年龄>>>:')
  84. teacher_obj.teacher_gender = input('请输入修改的老师性别>>>:')
  85. teacher_obj.teacher_salary = input('请输入修改的老师工资>>>:')
  86.  
  87. '''创建学生'''
  88. def create_student(self,student_name,student_gender,student_age,student_score,class_name):
  89. #创建学生对象
  90. student_obj = Student(student_name,student_gender,student_age,student_score)
  91. self.sch_student[student_name] = student_obj
  92. #建立学生和班级的关联关系
  93. class_obj = self.sch_class_room[class_name]
  94. class_obj.class_student[student_name] = student_obj
  95. #更新班级信息
  96. self.sch_class_room[class_name] =class_obj

  class_student.py

  1. #!/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3. # Author: Colin Yao
  4. class Student(object):
  5. def __init__(self,student_name,student_gender,student_age,student_score):
  6. #学生性命,性别,年龄,分数
  7. self.student_name = student_name
  8. self.student_gender = student_gender
  9. self.student_age = student_age
  10. self.student_score = student_score
  11. self.student_classroom = {}

  class_teacher.py

  1. #!/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3. # Author: Colin Yao
  4. class Teacher(object):
  5. def __init__(self,teacher_name,teacher_age,teacher_gender
  6. ,teacher_salary):
  7. self.teacher_name = teacher_name
  8. self.teacher_age = teacher_age
  9. self.teacher_gender = teacher_gender
  10. self.teacher_salary = teacher_salary
  11. self.teacher_classroom = {}
  12.  
  13. def add_tech_classroom(self,class_name,class_obj):
  14. self.teacher_classroom[class_name] = class_obj

  

 

Python作业选课系统(第六周)的更多相关文章

  1. Python作业-选课系统

    目录 Python作业-选课系统 days6作业-选课系统: 1. 程序说明 2. 思路和程序限制 3. 选课系统程序目录结构 4. 测试帐户说明 5. 程序测试过程 title: Python作业- ...

  2. python编辑选课系统

    一.需求分析 1. 创建北京.上海 2 所学校 2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开 3. 课程包含,周期,价格,通过学校创建课 ...

  3. Day7作业:选课系统

    这周的作业有点糙,迁就看吧,给大家点思路: readme: 需要安装模块: prettytable 测试帐号: 1.后台管理:admin/admin 只设定了这个后台管理帐号,没有写到数据库中 2.学 ...

  4. python之选课系统详解[功能未完善]

    作业需求 思路:1.先写出大体的类,比如学校类,学生类,课程类--   2.写出类里面大概的方法,比如学校类里面有创建讲师.创建班级-- 3.根据下面写出大致的代码,并实现其功能       遇到的困 ...

  5. python作业ATM(第五周)

    作业需求: 额度 15000或自定义. 实现购物商城,买东西加入 购物车,调用信用卡接口结账. 可以提现,手续费5%. 支持多账户登录. 支持账户间转账. 记录每月日常消费流水. 提供还款接口. AT ...

  6. [ python ] 面向对象 - 选课系统

    根据源程序进行改写:    原程序地址:http://www.cnblogs.com/lianzhilei/p/5985333.html  如有侵权立即删除.    感谢原作者将完整的代码提供参考.  ...

  7. Python 28 选课系统的讲解

    1.首先我们要对每一个新的项目有一个明确的思路,脑子是好东西,但是好记性不如烂笔头,所以,要把能想到的都写下来 2.然后就是创建项目的整体结构框架,比如说:conf ( 配置文件 ) .core (  ...

  8. python作业堡垒机(第十三周)

    作业需求: 1. 所有的用户操作日志要保留在数据库中 2. 每个用户登录堡垒机后,只需要选择具体要访问的设置,就连接上了,不需要再输入目标机器的访问密码 3. 允许用户对不同的目标设备有不同的访问权限 ...

  9. python作业三级菜单day1(第一周)

    一.作业需求: 1. 运行程序输出第一级菜单 2. 选择一级菜单某项,输出二级菜单,同理输出三级菜单 3. 菜单数据保存在文件中 4. 让用户选择是否要退出 5. 有返回上一级菜单的功能 二三级菜单文 ...

随机推荐

  1. 解决java图形界面label中文乱码

    第一:在你的具有main函数的类也即你应用运行的主类上点击右键,选择Run As中的Run Configurations,如下图:java,awt,中文方框,中文乱码第二,在Arguments标签下的 ...

  2. vue-cli3使用cdn方式引入moment.js

    1. index.html引入: <script src="https://cdn.bootcss.com/moment.js/2.20.1/moment.min.js"&g ...

  3. Django之contenttypes的应用

    Django contenttypes 应用 简介 contenttypes 是Django内置的一个应用,可以追踪项目中所有app和model的对应关系,并记录在ContentType表中. 每当我 ...

  4. dat.gui 上手

    dat.gui是款神器产品.一个调试利器.但是用起来很简单很简单 1:引用dat.gui.js. 2:实例化   this.gui = new dat.GUI(); 3:创建可设置一个数据对象.例如v ...

  5. javascript之彻底理解valueOf, toString

    参与运算的都是简单类型(一般就字符串和数字), 复杂类型是不参与运算的. ***当对象(非简单类型)用作键时,会先调用toString()方法把对象转化成字符串 var a = {},     b = ...

  6. 整合SSM框架应用

    普通方式 新建spring模块时引入如下内容: 启用devtools插件(热部署插件) idea需要做如下配置 settings-build-compiler->勾选build project ...

  7. 【bzoj2600】[Ioi2011]ricehub 双指针法

    题目描述 给出数轴上坐标从小到大的 $R$ 个点,坐标范围在 $1\sim L$ 之间.选出一段连续的点,满足:存在一个点,使得所有选出的点到其距离和不超过 $B$ .求最多能够选出多少点. $R\l ...

  8. 【bzoj2402】陶陶的难题II 分数规划+树链剖分+线段树+STL-vector+凸包+二分

    题目描述 输入 第一行包含一个正整数N,表示树中结点的个数.第二行包含N个正实数,第i个数表示xi (1<=xi<=10^5).第三行包含N个正实数,第i个数表示yi (1<=yi& ...

  9. [AT2363] [agc012_c] Tautonym Puzzle

    题目链接 AtCoder:https://agc012.contest.atcoder.jp/tasks/agc012_c 洛谷:https://www.luogu.org/problemnew/sh ...

  10. Linux内核分析第六周学习笔记——分析Linux内核创建一个新进程的过程

    Linux内核分析第六周学习笔记--分析Linux内核创建一个新进程的过程 zl + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/U ...