Move kindergarten_garden.py to u5 folder
This commit is contained in:
parent
5b720afa92
commit
8107a35409
35
u5/kindergarten_garden.py
Normal file
35
u5/kindergarten_garden.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
class NoSuchStudentException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class Garden:
|
||||||
|
def __init__(self, diagram, students=None):
|
||||||
|
self.diagram = diagram
|
||||||
|
if students is None:
|
||||||
|
self.students = [
|
||||||
|
"Alena", "Boris", "Cyril", "Daniel", "Eva", "František",
|
||||||
|
"Gitka", "Helena", "Ivana", "Jozef", "Karol", "Ladislav"
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
self.students = sorted(students)
|
||||||
|
|
||||||
|
self.plant_names = {
|
||||||
|
"G": "Tráva",
|
||||||
|
"C": "Ďatelina",
|
||||||
|
"R": "Reďkovky",
|
||||||
|
"V": "Fialky"
|
||||||
|
}
|
||||||
|
|
||||||
|
def plants(self, student):
|
||||||
|
if student not in self.students:
|
||||||
|
raise NoSuchStudentException("Student not found")
|
||||||
|
|
||||||
|
index = self.students.index(student)
|
||||||
|
start = index * 2
|
||||||
|
|
||||||
|
rows = self.diagram.splitlines()
|
||||||
|
row1 = rows[0]
|
||||||
|
row2 = rows[1]
|
||||||
|
|
||||||
|
letters = row1[start:start+2] + row2[start:start+2]
|
||||||
|
|
||||||
|
return [self.plant_names[char] for char in letters]
|
||||||
Loading…
Reference in New Issue
Block a user