From 8fb05588f2e3fa8e3aa26da9090e1e78aa273865 Mon Sep 17 00:00:00 2001 From: Arina Dohadailo Date: Tue, 13 Oct 2026 12:55:45 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20u5/kindergarten=5Fgarden.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- u5/kindergarten_garden.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/u5/kindergarten_garden.py b/u5/kindergarten_garden.py index 54c101c..191fe1b 100644 --- a/u5/kindergarten_garden.py +++ b/u5/kindergarten_garden.py @@ -6,17 +6,20 @@ DEFAULT_STUDENTS = [ "Gitka", "Helena", "Ivana", "Jozef", "Karol", "Ladislav", ] +PLANTS = {"G": "Trava", "C": "Datelina", "R": "Redkovky", "V": "Fialky"} class Garden(): - def __init__(self, diagram: str): - self.diagram: str = diagram - self.rows: str = diagram.splitlines() + def __init__(self, diagram, students=None): + self.diagram = diagram + self.rows = diagram.splitlines() + names = DEFAULT_STUDENTS if students is None else students + self.students = sorted(names) - def add_rows(self,row): - if isinstance(row,str): - raise ValueError("Row has to be string") - self.rows.append(row) + def plants(self, student): + if not isinstance(student,str): + raise TypeError("Student name has to be string") -garden = Garden("VVCG\nVVRC") -print([item[1:3] for item in garden.rows]) -garden.rows.append(Garden("s\ns")) -print(garden.rows) \ No newline at end of file + if student not in self.students: + raise NoSuchStudentException(f"Student {student} does not exist") + + start = self.students.index(student) * 2 + return [PLANTS[code] for row in self.rows for code in row[start:start + 2]]