class NoSuchStudentException(Exception): """Raised when plants are requested for a student not assigned a plot.""" DEFAULT_STUDENTS = ( "Alena", "Boris", "Cyril", "Daniel", "Eva", "František", "Gitka", "Helena", "Ivana", "Jozef", "Karol", "Ladislav", ) PLANT_NAMES = { "G": "Tráva", "C": "Ďatelina", "R": "Reďkovky", "V": "Fialky", } class Garden: def __init__(self, diagram, students=None): self.rows = diagram.splitlines() self.students = sorted(DEFAULT_STUDENTS if students is None else students) def plants(self, student): try: index = self.students.index(student) except ValueError: raise NoSuchStudentException( f"Žiak '{student}' nemá pridelený záhon." ) from None start = index * 2 return [ PLANT_NAMES[code] for row in self.rows for code in row[start : start + 2] ]