Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Patrik Tulach 2026-10-13 13:49:09 +02:00
parent 0257627d83
commit 53907e290c

22
u5/kindergarten_garden.py Normal file
View File

@ -0,0 +1,22 @@
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