This commit is contained in:
Your Name 2026-10-13 13:37:26 +02:00
parent 7e97fa4fe8
commit 88458d0739

45
u5/kindergarten_garden.py Normal file
View File

@ -0,0 +1,45 @@
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": "Trava",
"C": "Ďatelina",
"R": "Reďkovky",
"V": "Fialky",
}
class Garden:
def __init__(self, diagram, students=None):
self.row = 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]
]