Предизвикателства > Разбий ни ключалката > Решения > Решението на Вяра Тодорова

Резултати
1 точки от тестове
0 точки от учител

1 точки общо

1 успешни теста
0 неуспешни теста
Код

 1class LockPicker_6MI0600341:
 2    def __init__(self, lock):
 3        self.lock = lock
 4
 5    def unlock(self):
 6        arguments_in_pick = []
 7        while True:
 8            try:
 9                if self.lock.pick(*arguments_in_pick):
10                    return
11            except Exception as current_exception:
12                if isinstance(current_exception, TypeError) and current_exception.position is None:
13                    arguments_in_pick = [None] * current_exception.expected
14                elif isinstance(current_exception, TypeError):
15                    arguments_in_pick[current_exception.position - 1] = current_exception.expected()
16                elif isinstance(current_exception, ValueError):
17                    arguments_in_pick[current_exception.position - 1] = current_exception.expected
18                else:
19                    raise current_exception

Резултат от контролното:
19/25 верни отговора.
16 точки.
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

Дискусия
История

f1class LockPicker_6MI0600341:f1class LockPicker_6MI0600341:
2    def __init__(self, lock):2    def __init__(self, lock):
3        self.lock = lock3        self.lock = lock
44
5    def unlock(self):5    def unlock(self):
6        arguments_in_pick = []6        arguments_in_pick = []
7        while True:7        while True:
8            try:8            try:
9                if self.lock.pick(*arguments_in_pick):9                if self.lock.pick(*arguments_in_pick):
10                    return10                    return
11            except Exception as current_exception:11            except Exception as current_exception:
12                if isinstance(current_exception, TypeError) and current_exception.position is None:12                if isinstance(current_exception, TypeError) and current_exception.position is None:
t13                    arguments_in_pick = [None] * current_exception.positiont13                    arguments_in_pick = [None] * current_exception.expected
14                elif isinstance(current_exception, TypeError):14                elif isinstance(current_exception, TypeError):
15                    arguments_in_pick[current_exception.position - 1] = current_exception.expected()15                    arguments_in_pick[current_exception.position - 1] = current_exception.expected()
16                elif isinstance(current_exception, ValueError):16                elif isinstance(current_exception, ValueError):
17                    arguments_in_pick[current_exception.position - 1] = current_exception.expected17                    arguments_in_pick[current_exception.position - 1] = current_exception.expected
18                else:18                else:
19                    raise current_exception19                    raise current_exception
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op