1class LockPicker_5MI0600360:
2
3 def __init__(self, lock):
4 self.lock = lock
5
6 def unlock(self):
7 key = []
8 while True:
9 try:
10 self.lock.pick(*key)
11 except Exception as ex:
12 if isinstance(ex, TypeError) and not ex.position:
13 key.append(ex.expected * [0])
14 elif isinstance(ex, TypeError):
15 key[ex.position - 1] = key.expected()
16 else:
17 key[ex.position - 1] = key.expected
18 else:
19 break
Грешка при опит за отключване:
Traceback (most recent call last):
File "/tmp/solution.py", line 10, in unlock
self.lock.pick(*key)
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 15, in unlock
key[ex.position - 1] = key.expected()
^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'expected'
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_5MI0600360: | f | 1 | class LockPicker_5MI0600360: |
2 | 2 | ||||
3 | def __init__(self, lock): | 3 | def __init__(self, lock): | ||
4 | self.lock = lock | 4 | self.lock = lock | ||
5 | 5 | ||||
6 | def unlock(self): | 6 | def unlock(self): | ||
7 | key = [] | 7 | key = [] | ||
8 | while True: | 8 | while True: | ||
9 | try: | 9 | try: | ||
10 | self.lock.pick(*key) | 10 | self.lock.pick(*key) | ||
11 | except Exception as ex: | 11 | except Exception as ex: | ||
n | 12 | if issubclass(TypeError, ex.__class__) and not ex.position: | n | 12 | if isinstance(ex, TypeError) and not ex.position: |
13 | key.append(ex.expected * [0]) | 13 | key.append(ex.expected * [0]) | ||
t | 14 | elif issubclass(TypeError, ex.__class__): | t | 14 | elif isinstance(ex, TypeError): |
15 | key[ex.position - 1] = key.expected() | 15 | key[ex.position - 1] = key.expected() | ||
16 | else: | 16 | else: | ||
17 | key[ex.position - 1] = key.expected | 17 | key[ex.position - 1] = key.expected | ||
18 | else: | 18 | else: | ||
19 | break | 19 | break |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|