45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
class NoSuchStudentException(Exception):
|
|
pass
|
|
|
|
|
|
class Garden:
|
|
DEFAULT_STUDENTS = [
|
|
"Alena", "Boris", "Cyril", "Daniel",
|
|
"Eva", "František", "Gitka", "Helena",
|
|
"Ivana", "Jozef", "Karol", "Ladislav"
|
|
]
|
|
|
|
PLANT_MAP = {
|
|
'G': 'Tráva',
|
|
'C': 'Ďatelina',
|
|
'R': 'Reďkovky',
|
|
'V': 'Fialky'
|
|
}
|
|
|
|
def __init__(self, diagram, students=None):
|
|
if students is None:
|
|
self.students = self.DEFAULT_STUDENTS.copy()
|
|
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]
|