Обновить u5/kindergarten_garden.py

This commit is contained in:
Arina Dohadailo 2026-10-13 12:55:45 +00:00
parent 1829a679e2
commit 8fb05588f2

View File

@ -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)
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]]