Add u5/kindergarten_garden.py
This commit is contained in:
parent
ee6aa451fe
commit
f9e79faf64
44
u5/kindergarten_garden.py
Normal file
44
u5/kindergarten_garden.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
class NoSuchStudentIsFound(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Garden():
|
||||||
|
|
||||||
|
STUDENTS = [
|
||||||
|
"Alena", "Boris", "Cyril", "Daniel",
|
||||||
|
"Eva", "František", "Gitka", "Helena",
|
||||||
|
"Ivana", "Jozef", "Karol", "Ladislav"
|
||||||
|
]
|
||||||
|
|
||||||
|
PLANT_MAP = {
|
||||||
|
"G": "Tráva",
|
||||||
|
"C": "Ďatelina",
|
||||||
|
"R": "Reďkovky",
|
||||||
|
"V": "Fialky"
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, diagrm : str, students : list[str] = None):
|
||||||
|
self.diagrm: str = diagrm
|
||||||
|
self.rows: str = diagrm.splitlines()
|
||||||
|
|
||||||
|
if student is not None:
|
||||||
|
self.students = sorted(students)
|
||||||
|
else:
|
||||||
|
self.students = self.DEFULT_STUDENTS
|
||||||
|
|
||||||
|
def plants(self, students_name : str):
|
||||||
|
if students_name not in self.students:
|
||||||
|
raise NoSuchStudentIsFound(f"Učeň {student_name} neexistuje v tomto záhone.")
|
||||||
|
|
||||||
|
student_index = self.students.index(students_name)
|
||||||
|
|
||||||
|
start_col = student_index * 2
|
||||||
|
|
||||||
|
top_plants = self.rows[0][start_col:start_col + 2]
|
||||||
|
bottom_plants = self.rows[1][start_col:start_col + 2]
|
||||||
|
|
||||||
|
raw_chars = list(top_plants + bottom_plants)
|
||||||
|
|
||||||
|
result = [self.PLANT_MAP[char] for char in raw_chars]
|
||||||
|
|
||||||
|
return result
|
||||||
Loading…
Reference in New Issue
Block a user