This commit is contained in:
Oleksandr Mateshchuk 2026-10-13 11:59:18 +00:00
parent eec0ad030c
commit f12653c5d9

View File

@ -1,32 +1,35 @@
```python
class NoSuchStudentException(Exception): class NoSuchStudentException(Exception):
pass pass
class Garden: class Garden:
DEFAULT_STUDENTS = [ DEFAULT_STUDENTS = [
"Alice", "Bob", "Charlie", "David", "Alena", "Boris", "Cyril", "Daniel",
"Eve", "Fred", "Ginny", "Harriet", "Eva", "František", "Gitka", "Helena",
"Ileana", "Joseph", "Kincaid", "Larry" "Ivana", "Jozef", "Karol", "Ladislav"
] ]
PLANT_MAP = { PLANT_MAP = {
'G': 'tráva', 'G': 'Tráva',
'C': 'ďatelina', 'C': 'Ďatelina',
'R': 'reďkovky', 'R': 'Reďkovky',
'V': 'fialky' 'V': 'Fialky'
} }
def __init__(self, diagram, students=None): def __init__(self, diagram, students=None):
if students is None: if students is None:
self.students = sorted(self.DEFAULT_STUDENTS) self.students = self.DEFAULT_STUDENTS.copy()
else: else:
self.students = sorted(students) self.students = sorted(students)
self.r = diagram.splitlines() self.r = diagram.splitlines()
def plants(self, student): def plants(self, student):
if student not in self.students: if student not in self.students:
raise NoSuchStudentException(f"Student '{student}' is not assigned a plot.") raise NoSuchStudentException(
f"Student '{student}' is not assigned a plot."
)
i = self.students.index(student) i = self.students.index(student)
c1 = i * 2 c1 = i * 2
@ -39,4 +42,5 @@ class Garden:
self.r[1][c2] self.r[1][c2]
] ]
return [self.PLANT_MAP[code] for code in student_plants] return [self.PLANT_MAP[code] for code in student_plants]
```