1class LockPicker_9MI0600175:
2 """A class that unlocks a lock object by determining the arguments for its `pick` method."""
3
4 def __init__(self, lock):
5 """Initialize the LockPicker with a lock object."""
6 self._lock = lock
7
8 def unlock(self):
9 """Attempt to unlock the lock by trying different arguments with the `pick` method."""
10 unlock_arguments = []
11 while True:
12 try:
13 if self._lock.pick(*unlock_arguments):
14 return True
15 except TypeError as ex:
16 if ex.position is None and isinstance(ex.expected, int):
17 missing_arguments_count = ex.expected - len(unlock_arguments)
18 unlock_arguments.extend([None] * missing_arguments_count)
19 elif isinstance(ex.position, int) and isinstance(ex.expected, type):
20 unlock_arguments[ex.position - 1] = ex.expected()
21 except ValueError as ex:
22 if isinstance(ex.position, int):
23 unlock_arguments[ex.position - 1] = ex.expected
Резултат от контролното:
17/25 верни отговора.
14 точки.
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
13.11.2024 16:00
13.11.2024 16:01