1RESULTS = {
 2    "0MI0600128": { 
 3        "correct": "some_random_string",
 4        "points": "another_random_string",
 5    }
 6}
 7
 8class LockPicker_0MI0600128:
 9    def __init__(self, lock):
10        self.lock = lock  
11
12    def unlock(self):
13        attempt = []  
14        num_args = None  
15
16        while True:
17            try:
18                if num_args is not None:
19                    while len(attempt) < num_args:
20                        attempt.append(None)
21                result = self.lock.pick(*attempt)
22                return result  
23
24            except Exception as ex:
25                if isinstance(ex, TypeError):
26                    if ex.position is None:
27                        num_args = ex.expected
28                        attempt = [None] * num_args  
29                    else:
30                        if callable(ex.expected):
31                            attempt[ex.position - 1] = ex.expected()
32                        else:
33                            attempt[ex.position - 1] = ex.expected
34
35                elif isinstance(ex, ValueError):
36                    attempt[ex.position - 1] = ex.expected
Резултат от контролното:
    18/25 верни отговора.
    15 точки.
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
| t | 1 | RESULTS = { | t | 1 | RESULTS = { | 
| 2 | "0MI0600128": { | 2 | "0MI0600128": { | ||
| 3 | "correct": "some_random_string", | 3 | "correct": "some_random_string", | ||
| 4 | "points": "another_random_string", | 4 | "points": "another_random_string", | ||
| 5 | } | 5 | } | ||
| 6 | } | 6 | } | ||
| 7 | 7 | ||||
| 8 | class LockPicker_0MI0600128: | 8 | class LockPicker_0MI0600128: | ||
| 9 | def __init__(self, lock): | 9 | def __init__(self, lock): | ||
| 10 | self.lock = lock | 10 | self.lock = lock | ||
| 11 | 11 | ||||
| 12 | def unlock(self): | 12 | def unlock(self): | ||
| 13 | attempt = [] | 13 | attempt = [] | ||
| 14 | num_args = None | 14 | num_args = None | ||
| 15 | 15 | ||||
| 16 | while True: | 16 | while True: | ||
| 17 | try: | 17 | try: | ||
| 18 | if num_args is not None: | 18 | if num_args is not None: | ||
| 19 | while len(attempt) < num_args: | 19 | while len(attempt) < num_args: | ||
| 20 | attempt.append(None) | 20 | attempt.append(None) | ||
| 21 | result = self.lock.pick(*attempt) | 21 | result = self.lock.pick(*attempt) | ||
| 22 | return result | 22 | return result | ||
| 23 | 23 | ||||
| 24 | except Exception as ex: | 24 | except Exception as ex: | ||
| 25 | if isinstance(ex, TypeError): | 25 | if isinstance(ex, TypeError): | ||
| 26 | if ex.position is None: | 26 | if ex.position is None: | ||
| 27 | num_args = ex.expected | 27 | num_args = ex.expected | ||
| 28 | attempt = [None] * num_args | 28 | attempt = [None] * num_args | ||
| 29 | else: | 29 | else: | ||
| 30 | if callable(ex.expected): | 30 | if callable(ex.expected): | ||
| 31 | attempt[ex.position - 1] = ex.expected() | 31 | attempt[ex.position - 1] = ex.expected() | ||
| 32 | else: | 32 | else: | ||
| 33 | attempt[ex.position - 1] = ex.expected | 33 | attempt[ex.position - 1] = ex.expected | ||
| 34 | 34 | ||||
| 35 | elif isinstance(ex, ValueError): | 35 | elif isinstance(ex, ValueError): | ||
| 36 | attempt[ex.position - 1] = ex.expected | 36 | attempt[ex.position - 1] = ex.expected | ||
| 37 | 37 | 
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 
 | 
 | |||||||||
| n | n | 1 | RESULTS = { | ||
| 2 | "0MI0600128": { | ||||
| 3 | "correct": "some_random_string", | ||||
| 4 | "points": "another_random_string", | ||||
| 5 | } | ||||
| 6 | } | ||||
| 7 | |||||
| 1 | class LockPicker_0MI0600128: | 8 | class LockPicker_0MI0600128: | ||
| 2 | def __init__(self, lock): | 9 | def __init__(self, lock): | ||
| 3 | self.lock = lock | 10 | self.lock = lock | ||
| 4 | 11 | ||||
| 5 | def unlock(self): | 12 | def unlock(self): | ||
| n | 6 | attempt = [] | n | 13 | attempt = [] | 
| 7 | num_args = None | 14 | num_args = None | ||
| n | n | 15 | |||
| 8 | while True: | 16 | while True: | ||
| 9 | try: | 17 | try: | ||
| 10 | if num_args is not None: | 18 | if num_args is not None: | ||
| 11 | while len(attempt) < num_args: | 19 | while len(attempt) < num_args: | ||
| 12 | attempt.append(None) | 20 | attempt.append(None) | ||
| 13 | result = self.lock.pick(*attempt) | 21 | result = self.lock.pick(*attempt) | ||
| 14 | return result | 22 | return result | ||
| n | n | 23 | |||
| 15 | except Exception as ex: | 24 | except Exception as ex: | ||
| 16 | if isinstance(ex, TypeError): | 25 | if isinstance(ex, TypeError): | ||
| 17 | if ex.position is None: | 26 | if ex.position is None: | ||
| 18 | num_args = ex.expected | 27 | num_args = ex.expected | ||
| n | 19 | attempt = [None] * num_args | n | 28 | attempt = [None] * num_args | 
| 20 | else: | 29 | else: | ||
| n | n | 30 | if callable(ex.expected): | ||
| 21 | attempt[ex.position - 1] = ex.expected() | 31 | attempt[ex.position - 1] = ex.expected() | ||
| 32 | else: | ||||
| 33 | attempt[ex.position - 1] = ex.expected | ||||
| 34 | |||||
| 22 | elif isinstance(ex, ValueError): | 35 | elif isinstance(ex, ValueError): | ||
| 23 | attempt[ex.position - 1] = ex.expected | 36 | attempt[ex.position - 1] = ex.expected | ||
| t | t | 37 | 
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 
 | 
 | |||||||||
13.11.2024 21:00