Aktualizovat u5/kindergarted-garden.py

This commit is contained in:
Oleksandr Mateshchuk 2026-10-12 17:12:07 +00:00
parent 1bbec25a60
commit 8e53cac28d

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]