Update u5/kindergarten_garden.py
This commit is contained in:
parent
529cd9bfc9
commit
51efba9349
@ -1,9 +1,10 @@
|
|||||||
class NoSuchStudentException(Exception):
|
class NoSuchStudentException(Exception):
|
||||||
|
"""Виняток, що викликається, якщо ім'я учня не знайдено в саду."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Garden():
|
class Garden:
|
||||||
|
# Правильна назва константи з літерою 'a' (DEFAULT)
|
||||||
DEFAULT_STUDENTS = [
|
DEFAULT_STUDENTS = [
|
||||||
"Alena", "Boris", "Cyril", "Daniel",
|
"Alena", "Boris", "Cyril", "Daniel",
|
||||||
"Eva", "František", "Gitka", "Helena",
|
"Eva", "František", "Gitka", "Helena",
|
||||||
@ -17,20 +18,20 @@ class Garden():
|
|||||||
"V": "Fialky"
|
"V": "Fialky"
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, diagrm : str, students : list[str] = None):
|
def __init__(self, diagram: str, students: list[str] = None):
|
||||||
self.diagrm: str = diagrm
|
self.rows = diagram.splitlines()
|
||||||
self.rows: str = diagrm.splitlines()
|
|
||||||
|
|
||||||
if students is not None:
|
if students is not None:
|
||||||
self.students = sorted(students)
|
self.students = sorted(students)
|
||||||
else:
|
else:
|
||||||
self.students = self.DEFAULT_STUDENTS
|
self.students = self.DEFAULT_STUDENTS
|
||||||
|
|
||||||
def plants(self, students_name : str):
|
def plants(self, student_name: str) -> list[str]:
|
||||||
if students_name not in self.students:
|
if student_name not in self.students:
|
||||||
raise NoSuchStudentException(f"Učeň {student_name} neexistuje v tomto záhone.")
|
raise NoSuchStudentException(f"Učeň {student_name} neexistuje v tomto záhone.")
|
||||||
|
|
||||||
students_index = self.students.index(students_name)
|
student_index = self.students.index(student_name)
|
||||||
|
|
||||||
start_col = student_index * 2
|
start_col = student_index * 2
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user