Add u5/Školská záhrada
This commit is contained in:
parent
ac9290f67a
commit
37712fa259
44
u5/Školská záhrada
Normal file
44
u5/Školská záhrada
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