Add u5/kindergarten_garden.py
This commit is contained in:
parent
a00577862a
commit
9620c42ee6
44
u5/kindergarten_garden.py
Normal file
44
u5/kindergarten_garden.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
class NoSuchStudentException(Exception):
|
||||||
|
"""Raised when plants are requested for a student not assigned a plot."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Garden:
|
||||||
|
DEFAULT_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, diagram, students=None):
|
||||||
|
self.students = sorted(students)
|
||||||
|
self.rows = diagram.split("\n")
|
||||||
|
|
||||||
|
def plants(self, student_name):
|
||||||
|
if student_name not in self.students:
|
||||||
|
raise NoSuchStudentException("Ziak neexistuje")
|
||||||
|
|
||||||
|
index = self.student.index(student_name)
|
||||||
|
start = index *2
|
||||||
|
end = start +2
|
||||||
|
|
||||||
|
plant_chars = self.rows[0][start:end] +self.rows[1][start.end]
|
||||||
|
|
||||||
|
return [self.PLANT_MAP[char] for char in plant_chars]
|
||||||
Loading…
Reference in New Issue
Block a user