avp26/u5/kindergarten_garden.py
Patrik Tulach 53907e290c u5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 13:49:09 +02:00

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