Advertisement
horozov86

student_testing_exercise

Jul 25th, 2023
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. class Student:
  2.     def __init__(self, name: str, courses=None):
  3.         if courses is None:
  4.             courses = {}
  5.         self.name = name
  6.         self.courses = courses  # {course_name: [notes]}
  7.  
  8.     def enroll(self, course_name: str, notes, add_course_notes: str = ""):
  9.         if course_name in self.courses.keys():
  10.             [self.courses[course_name].append(x) for x in notes]
  11.             return "Course already added. Notes have been updated."
  12.  
  13.         if add_course_notes == "Y" or add_course_notes == "":
  14.             self.courses[course_name] = notes
  15.             return "Course and course notes have been added."
  16.  
  17.         self.courses[course_name] = []
  18.         return "Course has been added."
  19.  
  20.     def add_notes(self, course_name, notes):
  21.         if course_name in self.courses.keys():
  22.             self.courses[course_name].append(notes)
  23.             return "Notes have been updated"
  24.         raise Exception("Cannot add notes. Course not found.")
  25.  
  26.     def leave_course(self, course_name):
  27.         if course_name in self.courses.keys():
  28.             self.courses.pop(course_name)
  29.             return "Course has been removed"
  30.         raise Exception("Cannot remove course. Course not found.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement