1class LockPicker_1MI0600337:
2 """Unlock my lock."""
3
4 def __init__(self, lock):
5 self._lock = lock
6
7 def unlock(self):
8 DEFAULT_VALUE = 1
9 password = []
10 while True:
11 try:
12 if self._lock.pick(*password):
13 return True
14 except TypeError as exc:
15 if exc.position is None:
16 password = [DEFAULT_VALUE] * exc.expected
17 else:
18 of_unexpected_type = password[exc.position - 1]
19 password[exc.position - 1] = exc.expected(of_unexpected_type)
20 except ValueError as exc:
21 password[exc.position - 1] = exc.expected
Грешка при опит за отключване:
Traceback (most recent call last):
File "/tmp/solution.py", line 12, in unlock
if self._lock.pick(*password):
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/test.py", line 55, in pick
raise LockTypeError("You shall not pass!", position, type(slot))
test.LockTypeError: You shall not pass!
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/test.py", line 98, in <module>
test_unlocker(LockPicker(lock))
File "/usr/local/lib/python3.12/dist-packages/timeout_decorator/timeout_decorator.py", line 82, in new_function
return function(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/test.py", line 77, in test_unlocker
unlocker.unlock()
File "/tmp/solution.py", line 19, in unlock
password[exc.position - 1] = exc.expected(of_unexpected_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'int' object is not iterable
F
======================================================================
FAIL: test_picking (test.TestLockPicker.test_picking)
Ensure the lock is picked based on already stored boolean var.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 72, in test_picking
self.assertTrue(correct, "Не успя да отключиш.")
AssertionError: False is not true : Не успя да отключиш.
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (failures=1)
f | 1 | class LockPicker_1MI0600337: | f | 1 | class LockPicker_1MI0600337: |
2 | """Unlock my lock.""" | 2 | """Unlock my lock.""" | ||
3 | 3 | ||||
4 | def __init__(self, lock): | 4 | def __init__(self, lock): | ||
5 | self._lock = lock | 5 | self._lock = lock | ||
6 | 6 | ||||
7 | def unlock(self): | 7 | def unlock(self): | ||
8 | DEFAULT_VALUE = 1 | 8 | DEFAULT_VALUE = 1 | ||
9 | password = [] | 9 | password = [] | ||
10 | while True: | 10 | while True: | ||
11 | try: | 11 | try: | ||
12 | if self._lock.pick(*password): | 12 | if self._lock.pick(*password): | ||
13 | return True | 13 | return True | ||
t | 14 | except Exception as exc: | t | 14 | except TypeError as exc: |
15 | if isinstance(exc, TypeError): | ||||
16 | if exc.position is None: | 15 | if exc.position is None: | ||
17 | password = [DEFAULT_VALUE] * exc.expected | 16 | password = [DEFAULT_VALUE] * exc.expected | ||
18 | else: | 17 | else: | ||
19 | of_unexpected_type = password[exc.position - 1] | 18 | of_unexpected_type = password[exc.position - 1] | ||
20 | password[exc.position - 1] = exc.expected(of_unexpected_type) | 19 | password[exc.position - 1] = exc.expected(of_unexpected_type) | ||
21 | elif isinstance(exc, ValueError): | 20 | except ValueError as exc: | ||
22 | password[exc.position - 1] = exc.expected | 21 | password[exc.position - 1] = exc.expected |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|