class NoSuchStudentException(Exception): """Raised when plants are requested for a student not assigned a plot.""" pass class Garden: DEFAULT_STUDENTS = [ "Alena" "Boris" "Cyril" "Daniel" "Eva" "František" "Gitka" "Helena" "Ivana" "Jozef" "Karol" "Ladislav" ] PLANT_MAP = { "G":"Tráva", "C":"Ďatelina", "R":"Reďkovky", "V":"Fialky", } def __init__(self, diagram, students=DEFAULT_STUDENTS): self.students = sorted(students) self.rows = diagram.split("\n") def plants(self, student_name): if student_name not in self.students: raise NoSuchStudentException("Ziak neexistuje") index = self.student.index(student_name) start = index *2 end = start +2 plant_chars = self.rows[0][start:end] +self.rows[1][start.end] return [self.PLANT_MAP[char] for char in plant_chars]