sda
This commit is contained in:
parent
b87fc3fb49
commit
cd18736cfa
@ -4,10 +4,12 @@ class NoSuchStudentException(Exception):
|
||||
|
||||
class Garden:
|
||||
def __init__(self, diagram, students=None):
|
||||
# розбивка на 2 рядки
|
||||
rows = diagram.split("\n")
|
||||
self.row1 = rows[0]
|
||||
self.row2 = rows[1]
|
||||
|
||||
# деф. список або сорт. кастомного
|
||||
if students is None:
|
||||
self.students = [
|
||||
"Alena", "Boris", "Cyril", "Daniel", "Eva", "František",
|
||||
@ -16,6 +18,7 @@ class Garden:
|
||||
else:
|
||||
self.students = sorted(students)
|
||||
|
||||
# мапінг назв
|
||||
self.plant_names = {
|
||||
"G": "Tráva",
|
||||
"C": "Ďatelina",
|
||||
@ -24,12 +27,15 @@ class Garden:
|
||||
}
|
||||
|
||||
def plants(self, student):
|
||||
# чек студ.
|
||||
if student not in self.students:
|
||||
raise NoSuchStudentException()
|
||||
|
||||
# розрахунок інд.
|
||||
index = self.students.index(student)
|
||||
pos = index * 2
|
||||
|
||||
# вибір 4 симв.
|
||||
letters = [
|
||||
self.row1[pos],
|
||||
self.row1[pos + 1],
|
||||
@ -37,6 +43,7 @@ class Garden:
|
||||
self.row2[pos + 1]
|
||||
]
|
||||
|
||||
# конверт в назви
|
||||
result = []
|
||||
for letter in letters:
|
||||
result.append(self.plant_names[letter])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user