u5
This commit is contained in:
parent
971eeeffc7
commit
ec396b2a1f
41
u5/kindergarten_garden.py
Normal file
41
u5/kindergarten_garden.py
Normal file
@ -0,0 +1,41 @@
|
||||
class NoSuchStudentException(Exception):
|
||||
"""Raised when plants are requested for a student not assigned a plot."""
|
||||
|
||||
class Garden:
|
||||
PLANT_MAP ={
|
||||
'G': 'Tráva', 'C': 'Ďatelina', 'R': 'Reďkovky', 'V': 'Fialky'
|
||||
}
|
||||
|
||||
DEFAULT_STUDENTS = [
|
||||
"Alena", "Boris", "Cyril", "Daniel", "Eva", "František", "Gitka", "Helena",
|
||||
"Ivana", "Jozef", "Karol", "Ladislav"
|
||||
]
|
||||
|
||||
def __init__(self, diagram, students=None):
|
||||
self.diagram = diagram.splitlines()
|
||||
if students is None:
|
||||
self.students = sorted(self.DEFAULT_STUDENTS)
|
||||
else:
|
||||
self.students = sorted(students)
|
||||
|
||||
def plants(self, student_name): ## присутствует ли конкретный ученик которог запросила функция
|
||||
if student_name not in self.students:
|
||||
raise NoSuchStudentException(f"Žiak {student_name} sa nenachádza v zozname.")
|
||||
|
||||
# Находим индекс ученика в отсортированном списке
|
||||
idx = self.students.index(student_name)
|
||||
|
||||
# Вычисляем номера колонок для этого ученика
|
||||
col1 = idx * 2
|
||||
col2 = col1 + 1
|
||||
|
||||
# Собираем буквы с верхнего и нижнего ряда для этих двух колонок (всего 4 лунки)
|
||||
plant_codes = [
|
||||
self.diagram[0][col1], # верх 1
|
||||
self.diagram[0][col2], # верх 2
|
||||
self.diagram[1][col1], # ниp 1
|
||||
self.diagram[1][col2] # ниp 2
|
||||
]
|
||||
|
||||
# Переводим буквенные коды (G, C, R, V)
|
||||
return [self.PLANT_MAP[code] for code in plant_codes]
|
||||
Loading…
Reference in New Issue
Block a user