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):
|
|
self.rows = diagram.split("\n")
|
|
if students is None:
|
|
num_students = len(self.rows[0]) // 2
|
|
self.students = sorted(self.DEFAULT_STUDENTS[:num_students])
|
|
else:
|
|
self.students = sorted(students)
|
|
|
|
def plants(self, student_name):
|
|
if student_name not in self.students:
|
|
raise NoSuchStudentException("Ziak neexistuje")
|
|
|
|
index = self.students.index(student_name)
|
|
start = index * 2
|
|
end = start + 2
|
|
|
|
plant_chars = self.rows[0][start:end] + self.rows[1][start:end]
|
|
|
|
return [self.PLANT_MAP[char] for char in plant_chars] |