Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.42 KB | None | 0 0
  1. ##########
  2. class Students:
  3.  
  4. def __init__(self, students=[]):
  5. self.students = dict()
  6. for student in self.students:
  7. self.students[student.fetch_number()] = student
  8.  
  9. def add_student(self, student):
  10. ''' Add a student to the students dictionary.
  11. Return True if successful, else return False. '''
  12. # YOUR CODE HERE
  13. if student.student_number not in self.students:
  14. self.students[student.fetch_number()] = student
  15. return True
  16. return False
  17.  
  18. def add_students(self, students):
  19. ''' Add list of students to the students dictionary. '''
  20. # YOUR CODE HERE
  21. for student in students:
  22. self.add_student(student)
  23.  
  24. def fetch_students(self):
  25. ''' Return the students dictionary. '''
  26. return self.students
  27.  
  28. def fetch_student(self, studentID):
  29. ''' Return the student with this student number (ID). '''
  30. # YOUR CODE HERE
  31. return self.students[studentID]
  32.  
  33. def fetch_student_numbers(self):
  34. return list(self.students.keys())
  35.  
  36.  
  37.  
  38. class Student:
  39.  
  40. def __init__(self, first_name = 'First_Name',
  41. last_name = 'Last_Name',
  42. student_number = '0000'):
  43. self.first_name = first_name
  44. self.last_name = last_name
  45. self.student_number = student_number
  46. self.past_courses = [] # course numbers (IDs)
  47. self.current_courses = [] # course numbers (IDs)
  48.  
  49. def fetch_name(self):
  50. ''' Return the name of this student, (first_name, last_name). '''
  51. # YOUR CODE HERE
  52. return (self.first_name, self.last_name)
  53.  
  54. def fetch_number(self):
  55. ''' Return this students student number (ID). '''
  56. # YOUR CODE HERE
  57. return self.student_number
  58.  
  59. def add_past_courses(self, course_IDs = []):
  60. ''' Append this list of past course numbers (IDs)
  61. to the list of this student's past courses. '''
  62. # YOUR CODE HERE
  63. self.past_courses.extend(course_IDs)
  64.  
  65. def add_current_courses(self, course_IDs = []):
  66. ''' Append this list of current course numbers (IDs)
  67. to the list of this student's current courses. '''
  68. # YOUR CODE HERE
  69. self.current_courses.extend(course_IDs)
  70.  
  71. def add_course(self, courseID):
  72. ''' Append this course number (ID) to the list of current_courses. '''
  73. self.current_courses.append(courseID)
  74.  
  75. def fetch_past_courses(self): return self.past_courses
  76.  
  77. def fetch_current_courses(self): return self.current_courses
  78.  
  79. def drop_current_course(self, courseID):
  80. ''' Drop this course number (ID) from the list of current_courses.
  81. Return True if successful, else return False. '''
  82. #YOUR CODE HERE
  83. if courseID in self.current_courses:
  84. del self.current_courses[courseID]
  85. return True
  86. return False
  87.  
  88. def drop_all_current_courses(self):
  89. ''' Empty the current_courses list. '''
  90. self.current_courses = []
  91.  
  92. def current_to_past_courses(self):
  93. ''' Move all current course numbers (IDs) to the list of past_courses. '''
  94. self.past_courses += self.current_courses
  95. self.drop_all_current_courses()
  96.  
  97.  
  98.  
  99. class Courses:
  100.  
  101. def __init__(self, courses=[]):
  102. self.courses = dict()
  103. # This dictionary has course numbers (IDs) for its keys.
  104. for course in courses:
  105. self.courses[course.fetch_course_number()] = course
  106.  
  107. def add_course(self, course):
  108. ''' Add this course to the courses dictionary.
  109. Return True if successful, else return False. '''
  110. # YOUR CODE HERE
  111. if course.fetch_course_number() not in self.courses:
  112. self.courses[course.fetch_course_number()] = course
  113. return True
  114. return False
  115.  
  116. def add_courses(self, courses):
  117. # YOUR CODE HERE
  118. for course in courses:
  119. self.add_course(course)
  120.  
  121. def fetch_course_numbers(self):
  122. ''' Return a list of course numbers (IDs). '''
  123. return list(self.courses.keys())
  124.  
  125. def fetch_courses(self):
  126. ''' Return the dictionary of courses. '''
  127. return self.courses
  128.  
  129. def fetch_course(self, courseID):
  130. ''' Fetch the course with this course number (ID). '''
  131. #YOUR CODE HERE
  132. return self.courses[courseID]
  133.  
  134.  
  135. class Course:
  136.  
  137. def __init__(self, course_name = 'CS 000',
  138. course_number = '0000',
  139. semester = 'Fall',
  140. year = 2019,
  141. enrolled_students = []):
  142. ''' The enrolled_students argument is a list of student numbers (Ids) '''
  143.  
  144. self.course_name = course_name
  145. self.course_number = course_number
  146. self.semester = semester
  147. self.year = year
  148. # This dictionary has student numbers (IDs) as keys,
  149. # and the student's grade as the value.
  150. self.enrolled_students = {student : 'NG' for student in enrolled_students}
  151.  
  152. def fetch_course_name(self):
  153. ''' Return this course name. '''
  154. # YOUR CODE HERE
  155. return self.course_name
  156.  
  157. def fetch_course_number(self):
  158. ''' Return this course number. '''
  159. # YOUR CODE HERE
  160. return self.course_number
  161.  
  162. def fetch_enrolled_studentIDs(self):
  163. ''' Return a list of enrolled student numbers (IDs). '''
  164. return list(self.enrolled_students.keys())
  165.  
  166. def fetch_enrolled_students(self):
  167. ''' Return the dictionary of enrolled students and their grades. '''
  168. # YOUR CODE HERE
  169. return self.enrolled_students
  170.  
  171. def fetch_when_offered(self):
  172. ''' Return (semester, year) of when this course was offered. '''
  173. return (self.semester, self.year)
  174.  
  175. def enroll_student(self, studentID):
  176. ''' Enroll a student in the course.
  177. Return True if successful, else return False. '''
  178. # YOUR CODE HERE
  179. if studentID not in self.enrolled_students:
  180. self.enrolled_students[studentID] = 'NG'
  181. return True
  182. return False
  183.  
  184. def enroll_students(self, studentIDs):
  185. ''' Enroll multiple students in the course.
  186. Return True if successful, else return False. '''
  187. # YOUR CODE HERE
  188. for studentID in studentIDs:
  189. if studentID in self.enrolled_students:
  190. return False
  191. for studentID in studentIDs:
  192. self.enrolled_students[studentID] = 'NG'
  193. return True
  194.  
  195. def drop_student(self, studentID):
  196. ''' Drop this student from the course.
  197. Return True if successful, else return False. '''
  198. # YOUR CODE HERE
  199. if studentID in self.enrolled_students:
  200. del self.enrolled_students[studentID]
  201. return True
  202. return False
  203.  
  204. def submit_grade(self, studentID, grade):
  205. ''' Enter a grade for this student. '''
  206. # YOUR CODE HERE
  207. self.enrolled_students[studentID] = grade
  208.  
  209. def fetch_grades(self):
  210. ''' Return the enrolled_students dictionary. '''
  211. return self.enrolled_students
  212.  
  213. def fetch_grade(self, studentID):
  214. ''' Return this student’s grade. '''
  215. return self.enrolled_students[studentID]
  216.  
  217.  
  218.  
  219. def roll_courses():
  220. ''' A semester has finished, and the grades are all in. This function rolls all
  221. the current courses for each student from current_courses to past_courses. '''
  222. pass
  223. def compute_gpa(studentID):
  224. ''' Returns the GPA of the student with input student number(ID),
  225. rounded off to 2 decimal places. '''
  226. pass
  227. def compute_gpas(studentIDs):
  228. ''' Retuns a list of the gpas of all the students on the input list. '''
  229. pass
  230. def best_student():
  231. ''' Returns the name of the student with the highest GPA, in the format:
  232. FirstName LastName (with one space between them) '''
  233. pass
  234. def worst_student():
  235. ''' Returns the name of the student with the lowest GPA, in the format:
  236. FirstName LastName (with one space between them) '''
  237. pass
  238. def compute_mean_GPA():
  239. ''' Return the mean GPA of all students, rounded off to 2 decimal places. '''
  240. pass
  241.  
  242. def compute_mean_course_GPA(courseID):
  243. ''' Returns the mean GPA for the grades assigned to students who took this course. '''
  244. pass
  245.  
  246. all_courses = Courses()
  247. all_students = Students()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement