Aktualizovat u5/kindergarten_garden.py

This commit is contained in:
Oleksandr Mateshchuk 2026-10-12 17:35:21 +00:00
parent bda8f73909
commit 1cb5f81291

View File

@ -0,0 +1,42 @@
class NoSuchStudentException(Exception):
pass
class Garden:
DEFAULT_STUDENTS = [
"Alice", "Bob", "Charlie", "David",
"Eve", "Fred", "Ginny", "Harriet",
"Ileana", "Joseph", "Kincaid", "Larry"
]
PLANT_MAP = {
'G': 'tráva',
'C': 'ďatelina',
'R': 'reďkovky',
'V': 'fialky'
}
def __init__(self, diagram, students=None):
if students is None:
self.students = sorted(self.DEFAULT_STUDENTS)
else:
self.students = sorted(students)
self.r = diagram.splitlines()
def plants(self, student):
if student not in self.students:
raise NoSuchStudentException(f"Student '{student}' is not assigned a plot.")
i = self.students.index(student)
c1 = i * 2
c2 = i * 2 + 1
student_plants = [
self.r[0][c1],
self.r[0][c2],
self.r[1][c1],
self.r[1][c2]
]
return [self.PLANT_MAP[code] for code in student_plants]