u5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0257627d83
commit
53907e290c
22
u5/kindergarten_garden.py
Normal file
22
u5/kindergarten_garden.py
Normal 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
|
||||
Loading…
Reference in New Issue
Block a user