1def generate_type(ex_type):
2 """Generate a default value of the type, if it is an existing type"""
3 try:
4 return ex_type()
5 except Exception:
6 return None
7
8
9class LockPicker_1MI0600400:
10 def __init__(self, lock):
11 self.lock = lock
12
13 def unlock(self):
14 args = []
15
16 while True:
17 try:
18 if self.lock.pick(*args):
19 break
20 except Exception as ex:
21 if isinstance(ex, TypeError):
22 if ex.position is None:
23 args = [None] * ex.expected
24 else:
25 position = ex.position - 1
26 args[position] = generate_type(ex.expected)
27 elif isinstance(ex, ValueError):
28 position = ex.position - 1
29 args[position] = ex.expected
Резултат от контролното:
18/25 верни отговора.
15 точки.
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
| f | 1 | def generate_type(ex_type): | f | 1 | def generate_type(ex_type): |
| t | 2 | """Generate a default of value of the type, if it is existing type""" | t | 2 | """Generate a default value of the type, if it is an existing type""" |
| 3 | try: | 3 | try: | ||
| 4 | return ex_type() | 4 | return ex_type() | ||
| 5 | except Exception: | 5 | except Exception: | ||
| 6 | return None | 6 | return None | ||
| 7 | 7 | ||||
| 8 | 8 | ||||
| 9 | class LockPicker_1MI0600400: | 9 | class LockPicker_1MI0600400: | ||
| 10 | def __init__(self, lock): | 10 | def __init__(self, lock): | ||
| 11 | self.lock = lock | 11 | self.lock = lock | ||
| 12 | 12 | ||||
| 13 | def unlock(self): | 13 | def unlock(self): | ||
| 14 | args = [] | 14 | args = [] | ||
| 15 | 15 | ||||
| 16 | while True: | 16 | while True: | ||
| 17 | try: | 17 | try: | ||
| 18 | if self.lock.pick(*args): | 18 | if self.lock.pick(*args): | ||
| 19 | break | 19 | break | ||
| 20 | except Exception as ex: | 20 | except Exception as ex: | ||
| 21 | if isinstance(ex, TypeError): | 21 | if isinstance(ex, TypeError): | ||
| 22 | if ex.position is None: | 22 | if ex.position is None: | ||
| 23 | args = [None] * ex.expected | 23 | args = [None] * ex.expected | ||
| 24 | else: | 24 | else: | ||
| 25 | position = ex.position - 1 | 25 | position = ex.position - 1 | ||
| 26 | args[position] = generate_type(ex.expected) | 26 | args[position] = generate_type(ex.expected) | ||
| 27 | elif isinstance(ex, ValueError): | 27 | elif isinstance(ex, ValueError): | ||
| 28 | position = ex.position - 1 | 28 | position = ex.position - 1 | ||
| 29 | args[position] = ex.expected | 29 | args[position] = ex.expected |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
| n | 1 | def _generate_type(ex_type): | n | 1 | def generate_type(ex_type): |
| 2 | """Generate a default of value of the type, if it is existing type""" | 2 | """Generate a default of value of the type, if it is existing type""" | ||
| 3 | try: | 3 | try: | ||
| 4 | return ex_type() | 4 | return ex_type() | ||
| 5 | except Exception: | 5 | except Exception: | ||
| 6 | return None | 6 | return None | ||
| 7 | 7 | ||||
| 8 | 8 | ||||
| 9 | class LockPicker_1MI0600400: | 9 | class LockPicker_1MI0600400: | ||
| 10 | def __init__(self, lock): | 10 | def __init__(self, lock): | ||
| 11 | self.lock = lock | 11 | self.lock = lock | ||
| 12 | 12 | ||||
| 13 | def unlock(self): | 13 | def unlock(self): | ||
| 14 | args = [] | 14 | args = [] | ||
| 15 | 15 | ||||
| 16 | while True: | 16 | while True: | ||
| 17 | try: | 17 | try: | ||
| 18 | if self.lock.pick(*args): | 18 | if self.lock.pick(*args): | ||
| 19 | break | 19 | break | ||
| 20 | except Exception as ex: | 20 | except Exception as ex: | ||
| 21 | if isinstance(ex, TypeError): | 21 | if isinstance(ex, TypeError): | ||
| 22 | if ex.position is None: | 22 | if ex.position is None: | ||
| 23 | args = [None] * ex.expected | 23 | args = [None] * ex.expected | ||
| 24 | else: | 24 | else: | ||
| 25 | position = ex.position - 1 | 25 | position = ex.position - 1 | ||
| t | 26 | args[position] = _generate_type(ex.expected) | t | 26 | args[position] = generate_type(ex.expected) |
| 27 | elif isinstance(ex, ValueError): | 27 | elif isinstance(ex, ValueError): | ||
| 28 | position = ex.position - 1 | 28 | position = ex.position - 1 | ||
| 29 | args[position] = ex.expected | 29 | args[position] = ex.expected |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||