1class LockPicker_4MI0600234:
2
3 def __init__(self, lock):
4 self.lock = lock
5
6 def unlock(self):
7 args = []
8 args_count = 0
9 while True:
10 try:
11 self.lock.pick(*args)
12 except TypeError as ex:
13 if ex.position is None:
14 args_count = ex.expected
15 args = [None] * args_count
16 else:
17 args[ex.position - 1] = ex.expected()
18 except ValueError as ex:
19 args[ex.position - 1] = ex.expected
20 else:
21 break
Резултат от контролното:
21/25 верни отговора.
18 точки.
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
f | 1 | class LockPicker_4MI0600234: | f | 1 | class LockPicker_4MI0600234: |
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 | args = [] | 7 | args = [] | ||
8 | args_count = 0 | 8 | args_count = 0 | ||
9 | while True: | 9 | while True: | ||
10 | try: | 10 | try: | ||
11 | self.lock.pick(*args) | 11 | self.lock.pick(*args) | ||
12 | except TypeError as ex: | 12 | except TypeError as ex: | ||
13 | if ex.position is None: | 13 | if ex.position is None: | ||
14 | args_count = ex.expected | 14 | args_count = ex.expected | ||
15 | args = [None] * args_count | 15 | args = [None] * args_count | ||
16 | else: | 16 | else: | ||
n | 17 | args[ex.position - 1] = self.__generate_value_of_type__(ex.expected) | n | 17 | args[ex.position - 1] = ex.expected() |
18 | except ValueError as ex: | 18 | except ValueError as ex: | ||
19 | args[ex.position - 1] = ex.expected | 19 | args[ex.position - 1] = ex.expected | ||
20 | else: | 20 | else: | ||
21 | break | 21 | break | ||
t | 22 | t | |||
23 | def __generate_value_of_type__(self, expected_type): | ||||
24 | if expected_type is int: | ||||
25 | return 1 | ||||
26 | elif expected_type is float: | ||||
27 | return 0.1 | ||||
28 | elif expected_type is str: | ||||
29 | return '' | ||||
30 | elif expected_type is bool: | ||||
31 | return False | ||||
32 | elif expected_type is list: | ||||
33 | return [] | ||||
34 | elif expected_type is tuple: | ||||
35 | return () | ||||
36 | elif expected_type is set: | ||||
37 | return set() | ||||
38 | elif expected_type is dict: | ||||
39 | return dict() | ||||
40 | elif expected_type is complex: | ||||
41 | return 1 + 1j | ||||
42 | elif expected_type is frozenset: | ||||
43 | return frozenset() | ||||
44 | else: | ||||
45 | return None |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|