Обновить u5/kindergarten_garden.py
This commit is contained in:
parent
1829a679e2
commit
8fb05588f2
@ -6,17 +6,20 @@ DEFAULT_STUDENTS = [
|
|||||||
"Gitka", "Helena", "Ivana", "Jozef", "Karol", "Ladislav",
|
"Gitka", "Helena", "Ivana", "Jozef", "Karol", "Ladislav",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
PLANTS = {"G": "Trava", "C": "Datelina", "R": "Redkovky", "V": "Fialky"}
|
||||||
class Garden():
|
class Garden():
|
||||||
def __init__(self, diagram: str):
|
def __init__(self, diagram, students=None):
|
||||||
self.diagram: str = diagram
|
self.diagram = diagram
|
||||||
self.rows: str = diagram.splitlines()
|
self.rows = diagram.splitlines()
|
||||||
|
names = DEFAULT_STUDENTS if students is None else students
|
||||||
|
self.students = sorted(names)
|
||||||
|
|
||||||
def add_rows(self,row):
|
def plants(self, student):
|
||||||
if isinstance(row,str):
|
if not isinstance(student,str):
|
||||||
raise ValueError("Row has to be string")
|
raise TypeError("Student name has to be string")
|
||||||
self.rows.append(row)
|
|
||||||
|
|
||||||
garden = Garden("VVCG\nVVRC")
|
if student not in self.students:
|
||||||
print([item[1:3] for item in garden.rows])
|
raise NoSuchStudentException(f"Student {student} does not exist")
|
||||||
garden.rows.append(Garden("s\ns"))
|
|
||||||
print(garden.rows)
|
start = self.students.index(student) * 2
|
||||||
|
return [PLANTS[code] for row in self.rows for code in row[start:start + 2]]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user