diff --git a/u5/kindergarten_garden.py b/u5/kindergarten_garden.py index 101def1..bb43c2b 100644 --- a/u5/kindergarten_garden.py +++ b/u5/kindergarten_garden.py @@ -1,15 +1,16 @@ class NoSuchStudentException(Exception): + """Виняток, що викликається, якщо ім'я учня не знайдено в саду.""" pass -class Garden(): - +class Garden: + # Правильна назва константи з літерою 'a' (DEFAULT) DEFAULT_STUDENTS = [ - "Alena", "Boris", "Cyril", "Daniel", - "Eva", "František", "Gitka", "Helena", + "Alena", "Boris", "Cyril", "Daniel", + "Eva", "František", "Gitka", "Helena", "Ivana", "Jozef", "Karol", "Ladislav" ] - + PLANT_MAP = { "G": "Tráva", "C": "Ďatelina", @@ -17,28 +18,28 @@ class Garden(): "V": "Fialky" } - def __init__(self, diagrm : str, students : list[str] = None): - self.diagrm: str = diagrm - self.rows: str = diagrm.splitlines() - + def __init__(self, diagram: str, students: list[str] = None): + self.rows = diagram.splitlines() + + if students is not None: self.students = sorted(students) else: self.students = self.DEFAULT_STUDENTS - def plants(self, students_name : str): - if students_name not in self.students: + def plants(self, student_name: str) -> list[str]: + if student_name not in self.students: raise NoSuchStudentException(f"Učeň {student_name} neexistuje v tomto záhone.") - - students_index = self.students.index(students_name) - + + student_index = self.students.index(student_name) + start_col = student_index * 2 - + top_plants = self.rows[0][start_col:start_col + 2] bottom_plants = self.rows[1][start_col:start_col + 2] - + raw_chars = list(top_plants + bottom_plants) - + result = [self.PLANT_MAP[char] for char in raw_chars] - + return result \ No newline at end of file