22 lines
802 B
Python
22 lines
802 B
Python
class NoSuchStudentException(Exception):
|
|
pass
|
|
|
|
|
|
class Garden:
|
|
STUDENTS = ["Alena", "Boris", "Cyril", "Daniel", "Eva", "František",
|
|
"Gitka", "Helena", "Ivana", "Jozef", "Karol", "Ladislav"]
|
|
PLANTS = {"G": "Tráva", "C": "Ďatelina", "R": "Reďkovky", "V": "Fialky"}
|
|
|
|
def __init__(self, diagram, students=None):
|
|
self.rows = diagram.split("\n")
|
|
self.students = sorted(students) if students else self.STUDENTS
|
|
|
|
def plants(self, student):
|
|
if student not in self.students:
|
|
raise NoSuchStudentException(student)
|
|
i = self.students.index(student) * 2
|
|
letters = self.rows[0][i:i+2] + self.rows[1][i:i+2]
|
|
result = []
|
|
for letter in letters:
|
|
result.append(self.PLANTS[letter])
|
|
return result |