1class LockPicker_31593:
2 def __init__(self, lock):
3 self.lock = lock
4
5 def unlock(self):
6 try:
7 self.lock.pick()
8 except Exception as ex:
9 self.lock_args = [None for _ in range(ex.expected)]
10
11 while True:
12 try:
13 self.lock.pick(*self.lock_args)
14 return
15 except Exception as ex:
16 if isinstance(ex, TypeError):
17 self.lock_args[ex.position - 1] = ex.expected()
18 elif isinstance(ex, ValueError):
19 self.lock_args[ex.position - 1] = ex.expected
Резултат от контролното:
18/25 верни отговора.
15 точки.
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
Георги Кунчев
13.11.2024 11:32По принцип няма да тестваме с такъв случай, затова ще си позволя да ти споделя потенциален проблем.
Ако ключалката не очаква никакви аргументи, `self.lock_args` ще ти остане недефинирано и после влизаш в безкраен цикъл.
Пак да кажа - не е нужно да го оправяш, защото няма да тестваме за празна ключалка.
|
t | 1 | class LockPicker_FN31593: | t | 1 | class LockPicker_31593: |
2 | def __init__(self, lock): | 2 | def __init__(self, lock): | ||
3 | self.lock = lock | 3 | self.lock = lock | ||
4 | 4 | ||||
5 | def unlock(self): | 5 | def unlock(self): | ||
6 | try: | 6 | try: | ||
7 | self.lock.pick() | 7 | self.lock.pick() | ||
8 | except Exception as ex: | 8 | except Exception as ex: | ||
9 | self.lock_args = [None for _ in range(ex.expected)] | 9 | self.lock_args = [None for _ in range(ex.expected)] | ||
10 | 10 | ||||
11 | while True: | 11 | while True: | ||
12 | try: | 12 | try: | ||
13 | self.lock.pick(*self.lock_args) | 13 | self.lock.pick(*self.lock_args) | ||
14 | return | 14 | return | ||
15 | except Exception as ex: | 15 | except Exception as ex: | ||
16 | if isinstance(ex, TypeError): | 16 | if isinstance(ex, TypeError): | ||
17 | self.lock_args[ex.position - 1] = ex.expected() | 17 | self.lock_args[ex.position - 1] = ex.expected() | ||
18 | elif isinstance(ex, ValueError): | 18 | elif isinstance(ex, ValueError): | ||
19 | self.lock_args[ex.position - 1] = ex.expected | 19 | self.lock_args[ex.position - 1] = ex.expected |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
t | 1 | class LockPicker_FN31593: | t | 1 | class LockPicker_FN31593: |
2 | def __init__(self, lock): | 2 | def __init__(self, lock): | ||
3 | self.lock = lock | 3 | self.lock = lock | ||
4 | 4 | ||||
5 | def unlock(self): | 5 | def unlock(self): | ||
6 | try: | 6 | try: | ||
7 | self.lock.pick() | 7 | self.lock.pick() | ||
8 | except Exception as ex: | 8 | except Exception as ex: | ||
9 | self.lock_args = [None for _ in range(ex.expected)] | 9 | self.lock_args = [None for _ in range(ex.expected)] | ||
10 | 10 | ||||
11 | while True: | 11 | while True: | ||
12 | try: | 12 | try: | ||
13 | self.lock.pick(*self.lock_args) | 13 | self.lock.pick(*self.lock_args) | ||
14 | return | 14 | return | ||
15 | except Exception as ex: | 15 | except Exception as ex: | ||
16 | if isinstance(ex, TypeError): | 16 | if isinstance(ex, TypeError): | ||
17 | self.lock_args[ex.position - 1] = ex.expected() | 17 | self.lock_args[ex.position - 1] = ex.expected() | ||
18 | elif isinstance(ex, ValueError): | 18 | elif isinstance(ex, ValueError): | ||
19 | self.lock_args[ex.position - 1] = ex.expected | 19 | self.lock_args[ex.position - 1] = ex.expected |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|