Aktualizovat u5/kindergarten_garden.py
This commit is contained in:
parent
d762676912
commit
aa7e6b0352
@ -1,32 +1,35 @@
|
||||
```python
|
||||
class NoSuchStudentException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class Garden:
|
||||
DEFAULT_STUDENTS = [
|
||||
"Alice", "Bob", "Charlie", "David",
|
||||
"Eve", "Fred", "Ginny", "Harriet",
|
||||
"Ileana", "Joseph", "Kincaid", "Larry"
|
||||
"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'
|
||||
'G': 'Tráva',
|
||||
'C': 'Ďatelina',
|
||||
'R': 'Reďkovky',
|
||||
'V': 'Fialky'
|
||||
}
|
||||
|
||||
def __init__(self, diagram, students=None):
|
||||
if students is None:
|
||||
self.students = sorted(self.DEFAULT_STUDENTS)
|
||||
self.students = self.DEFAULT_STUDENTS.copy()
|
||||
else:
|
||||
self.students = sorted(students)
|
||||
|
||||
|
||||
self.r = diagram.splitlines()
|
||||
|
||||
def plants(self, student):
|
||||
if student not in self.students:
|
||||
raise NoSuchStudentException(f"Student '{student}' is not assigned a plot.")
|
||||
raise NoSuchStudentException(
|
||||
f"Student '{student}' is not assigned a plot."
|
||||
)
|
||||
|
||||
i = self.students.index(student)
|
||||
c1 = i * 2
|
||||
@ -39,4 +42,5 @@ class Garden:
|
||||
self.r[1][c2]
|
||||
]
|
||||
|
||||
return [self.PLANT_MAP[code] for code in student_plants]
|
||||
return [self.PLANT_MAP[code] for code in student_plants]
|
||||
```
|
||||
|
||||
Loading…
Reference in New Issue
Block a user