1class LockPicker_gkunchev:
2 """Pick a lock. It's that simple!"""
3
4 def __init__(self, lock):
5 """Store the lock passed when initializing."""
6 self._lock = lock
7
8 def unlock(self):
9 """Try to pick the lock. No - there is no try - PICK THE LOCK!"""
10 # Start by passing empty argument list
11 # to determine the expected argument count
12 combination = []
13 while True:
14 try:
15 self._lock.pick(*combination)
16 except TypeError as ex:
17 # This case defines the number of expected arguments
18 if ex.position is None:
19 # Try with as many None-s as the lock expects as arg count
20 combination = [None for _ in range(ex.expected)]
21 # This case means the arg count is correct
22 # An unexpected type was passed so pass empty instance
23 # from the expected type
24 else:
25 combination[ex.position - 1] = ex.expected()
26 # An unexpected value of the correct type was found
27 # pass the expected value instead
28 except ValueError as ex:
29 combination[ex.position - 1] = ex.expected
30 # No exception means that the lock is unlocked
31 else:
32 break
Резултат от контролното:
25/25 верни отговора.
20 точки.
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
n | 1 | class LockPicker_gkunchev1: | n | 1 | class LockPicker_gkunchev: |
2 | """Pick a lock. It's that simple!""" | 2 | """Pick a lock. It's that simple!""" | ||
3 | 3 | ||||
4 | def __init__(self, lock): | 4 | def __init__(self, lock): | ||
5 | """Store the lock passed when initializing.""" | 5 | """Store the lock passed when initializing.""" | ||
6 | self._lock = lock | 6 | self._lock = lock | ||
7 | 7 | ||||
8 | def unlock(self): | 8 | def unlock(self): | ||
9 | """Try to pick the lock. No - there is no try - PICK THE LOCK!""" | 9 | """Try to pick the lock. No - there is no try - PICK THE LOCK!""" | ||
10 | # Start by passing empty argument list | 10 | # Start by passing empty argument list | ||
11 | # to determine the expected argument count | 11 | # to determine the expected argument count | ||
12 | combination = [] | 12 | combination = [] | ||
13 | while True: | 13 | while True: | ||
14 | try: | 14 | try: | ||
15 | self._lock.pick(*combination) | 15 | self._lock.pick(*combination) | ||
16 | except TypeError as ex: | 16 | except TypeError as ex: | ||
17 | # This case defines the number of expected arguments | 17 | # This case defines the number of expected arguments | ||
18 | if ex.position is None: | 18 | if ex.position is None: | ||
19 | # Try with as many None-s as the lock expects as arg count | 19 | # Try with as many None-s as the lock expects as arg count | ||
20 | combination = [None for _ in range(ex.expected)] | 20 | combination = [None for _ in range(ex.expected)] | ||
21 | # This case means the arg count is correct | 21 | # This case means the arg count is correct | ||
22 | # An unexpected type was passed so pass empty instance | 22 | # An unexpected type was passed so pass empty instance | ||
23 | # from the expected type | 23 | # from the expected type | ||
24 | else: | 24 | else: | ||
25 | combination[ex.position - 1] = ex.expected() | 25 | combination[ex.position - 1] = ex.expected() | ||
26 | # An unexpected value of the correct type was found | 26 | # An unexpected value of the correct type was found | ||
27 | # pass the expected value instead | 27 | # pass the expected value instead | ||
28 | except ValueError as ex: | 28 | except ValueError as ex: | ||
29 | combination[ex.position - 1] = ex.expected | 29 | combination[ex.position - 1] = ex.expected | ||
30 | # No exception means that the lock is unlocked | 30 | # No exception means that the lock is unlocked | ||
31 | else: | 31 | else: | ||
32 | break | 32 | break | ||
t | 33 | t | |||
34 | print('This is a test') |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
t | 1 | class LockPicker_gkunchev1: | t | 1 | class LockPicker_gkunchev1: |
2 | """Pick a lock. It's that simple!""" | 2 | """Pick a lock. It's that simple!""" | ||
3 | 3 | ||||
4 | def __init__(self, lock): | 4 | def __init__(self, lock): | ||
5 | """Store the lock passed when initializing.""" | 5 | """Store the lock passed when initializing.""" | ||
6 | self._lock = lock | 6 | self._lock = lock | ||
7 | 7 | ||||
8 | def unlock(self): | 8 | def unlock(self): | ||
9 | """Try to pick the lock. No - there is no try - PICK THE LOCK!""" | 9 | """Try to pick the lock. No - there is no try - PICK THE LOCK!""" | ||
10 | # Start by passing empty argument list | 10 | # Start by passing empty argument list | ||
11 | # to determine the expected argument count | 11 | # to determine the expected argument count | ||
12 | combination = [] | 12 | combination = [] | ||
13 | while True: | 13 | while True: | ||
14 | try: | 14 | try: | ||
15 | self._lock.pick(*combination) | 15 | self._lock.pick(*combination) | ||
16 | except TypeError as ex: | 16 | except TypeError as ex: | ||
17 | # This case defines the number of expected arguments | 17 | # This case defines the number of expected arguments | ||
18 | if ex.position is None: | 18 | if ex.position is None: | ||
19 | # Try with as many None-s as the lock expects as arg count | 19 | # Try with as many None-s as the lock expects as arg count | ||
20 | combination = [None for _ in range(ex.expected)] | 20 | combination = [None for _ in range(ex.expected)] | ||
21 | # This case means the arg count is correct | 21 | # This case means the arg count is correct | ||
22 | # An unexpected type was passed so pass empty instance | 22 | # An unexpected type was passed so pass empty instance | ||
23 | # from the expected type | 23 | # from the expected type | ||
24 | else: | 24 | else: | ||
25 | combination[ex.position - 1] = ex.expected() | 25 | combination[ex.position - 1] = ex.expected() | ||
26 | # An unexpected value of the correct type was found | 26 | # An unexpected value of the correct type was found | ||
27 | # pass the expected value instead | 27 | # pass the expected value instead | ||
28 | except ValueError as ex: | 28 | except ValueError as ex: | ||
29 | combination[ex.position - 1] = ex.expected | 29 | combination[ex.position - 1] = ex.expected | ||
30 | # No exception means that the lock is unlocked | 30 | # No exception means that the lock is unlocked | ||
31 | else: | 31 | else: | ||
32 | break | 32 | break | ||
33 | 33 | ||||
34 | print('This is a test') | 34 | print('This is a test') |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
n | 1 | class LockPicker_gkunchev: | n | 1 | class LockPicker_gkunchev1: |
2 | """Pick a lock. It's that simple!""" | 2 | """Pick a lock. It's that simple!""" | ||
3 | 3 | ||||
4 | def __init__(self, lock): | 4 | def __init__(self, lock): | ||
5 | """Store the lock passed when initializing.""" | 5 | """Store the lock passed when initializing.""" | ||
6 | self._lock = lock | 6 | self._lock = lock | ||
7 | 7 | ||||
8 | def unlock(self): | 8 | def unlock(self): | ||
9 | """Try to pick the lock. No - there is no try - PICK THE LOCK!""" | 9 | """Try to pick the lock. No - there is no try - PICK THE LOCK!""" | ||
10 | # Start by passing empty argument list | 10 | # Start by passing empty argument list | ||
11 | # to determine the expected argument count | 11 | # to determine the expected argument count | ||
12 | combination = [] | 12 | combination = [] | ||
13 | while True: | 13 | while True: | ||
14 | try: | 14 | try: | ||
15 | self._lock.pick(*combination) | 15 | self._lock.pick(*combination) | ||
16 | except TypeError as ex: | 16 | except TypeError as ex: | ||
17 | # This case defines the number of expected arguments | 17 | # This case defines the number of expected arguments | ||
18 | if ex.position is None: | 18 | if ex.position is None: | ||
19 | # Try with as many None-s as the lock expects as arg count | 19 | # Try with as many None-s as the lock expects as arg count | ||
20 | combination = [None for _ in range(ex.expected)] | 20 | combination = [None for _ in range(ex.expected)] | ||
21 | # This case means the arg count is correct | 21 | # This case means the arg count is correct | ||
22 | # An unexpected type was passed so pass empty instance | 22 | # An unexpected type was passed so pass empty instance | ||
23 | # from the expected type | 23 | # from the expected type | ||
24 | else: | 24 | else: | ||
25 | combination[ex.position - 1] = ex.expected() | 25 | combination[ex.position - 1] = ex.expected() | ||
26 | # An unexpected value of the correct type was found | 26 | # An unexpected value of the correct type was found | ||
27 | # pass the expected value instead | 27 | # pass the expected value instead | ||
28 | except ValueError as ex: | 28 | except ValueError as ex: | ||
29 | combination[ex.position - 1] = ex.expected | 29 | combination[ex.position - 1] = ex.expected | ||
30 | # No exception means that the lock is unlocked | 30 | # No exception means that the lock is unlocked | ||
31 | else: | 31 | else: | ||
32 | break | 32 | break | ||
t | t | 33 | |||
34 | print('This is a test') |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
t | 1 | class LockPicker_666: | t | 1 | class LockPicker_gkunchev: |
2 | """Pick a lock. It's that simple!""" | 2 | """Pick a lock. It's that simple!""" | ||
3 | 3 | ||||
4 | def __init__(self, lock): | 4 | def __init__(self, lock): | ||
5 | """Store the lock passed when initializing.""" | 5 | """Store the lock passed when initializing.""" | ||
6 | self._lock = lock | 6 | self._lock = lock | ||
7 | 7 | ||||
8 | def unlock(self): | 8 | def unlock(self): | ||
9 | """Try to pick the lock. No - there is no try - PICK THE LOCK!""" | 9 | """Try to pick the lock. No - there is no try - PICK THE LOCK!""" | ||
10 | # Start by passing empty argument list | 10 | # Start by passing empty argument list | ||
11 | # to determine the expected argument count | 11 | # to determine the expected argument count | ||
12 | combination = [] | 12 | combination = [] | ||
13 | while True: | 13 | while True: | ||
14 | try: | 14 | try: | ||
15 | self._lock.pick(*combination) | 15 | self._lock.pick(*combination) | ||
16 | except TypeError as ex: | 16 | except TypeError as ex: | ||
17 | # This case defines the number of expected arguments | 17 | # This case defines the number of expected arguments | ||
18 | if ex.position is None: | 18 | if ex.position is None: | ||
19 | # Try with as many None-s as the lock expects as arg count | 19 | # Try with as many None-s as the lock expects as arg count | ||
20 | combination = [None for _ in range(ex.expected)] | 20 | combination = [None for _ in range(ex.expected)] | ||
21 | # This case means the arg count is correct | 21 | # This case means the arg count is correct | ||
22 | # An unexpected type was passed so pass empty instance | 22 | # An unexpected type was passed so pass empty instance | ||
23 | # from the expected type | 23 | # from the expected type | ||
24 | else: | 24 | else: | ||
25 | combination[ex.position - 1] = ex.expected() | 25 | combination[ex.position - 1] = ex.expected() | ||
26 | # An unexpected value of the correct type was found | 26 | # An unexpected value of the correct type was found | ||
27 | # pass the expected value instead | 27 | # pass the expected value instead | ||
28 | except ValueError as ex: | 28 | except ValueError as ex: | ||
29 | combination[ex.position - 1] = ex.expected | 29 | combination[ex.position - 1] = ex.expected | ||
30 | # No exception means that the lock is unlocked | 30 | # No exception means that the lock is unlocked | ||
31 | else: | 31 | else: | ||
32 | break | 32 | break |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
t | 1 | class LockPicker_gkunchev: | t | 1 | class LockPicker_666: |
2 | """Pick a lock. It's that simple!""" | 2 | """Pick a lock. It's that simple!""" | ||
3 | 3 | ||||
4 | def __init__(self, lock): | 4 | def __init__(self, lock): | ||
5 | """Store the lock passed when initializing.""" | 5 | """Store the lock passed when initializing.""" | ||
6 | self._lock = lock | 6 | self._lock = lock | ||
7 | 7 | ||||
8 | def unlock(self): | 8 | def unlock(self): | ||
9 | """Try to pick the lock. No - there is no try - PICK THE LOCK!""" | 9 | """Try to pick the lock. No - there is no try - PICK THE LOCK!""" | ||
10 | # Start by passing empty argument list | 10 | # Start by passing empty argument list | ||
11 | # to determine the expected argument count | 11 | # to determine the expected argument count | ||
12 | combination = [] | 12 | combination = [] | ||
13 | while True: | 13 | while True: | ||
14 | try: | 14 | try: | ||
15 | self._lock.pick(*combination) | 15 | self._lock.pick(*combination) | ||
16 | except TypeError as ex: | 16 | except TypeError as ex: | ||
17 | # This case defines the number of expected arguments | 17 | # This case defines the number of expected arguments | ||
18 | if ex.position is None: | 18 | if ex.position is None: | ||
19 | # Try with as many None-s as the lock expects as arg count | 19 | # Try with as many None-s as the lock expects as arg count | ||
20 | combination = [None for _ in range(ex.expected)] | 20 | combination = [None for _ in range(ex.expected)] | ||
21 | # This case means the arg count is correct | 21 | # This case means the arg count is correct | ||
22 | # An unexpected type was passed so pass empty instance | 22 | # An unexpected type was passed so pass empty instance | ||
23 | # from the expected type | 23 | # from the expected type | ||
24 | else: | 24 | else: | ||
25 | combination[ex.position - 1] = ex.expected() | 25 | combination[ex.position - 1] = ex.expected() | ||
26 | # An unexpected value of the correct type was found | 26 | # An unexpected value of the correct type was found | ||
27 | # pass the expected value instead | 27 | # pass the expected value instead | ||
28 | except ValueError as ex: | 28 | except ValueError as ex: | ||
29 | combination[ex.position - 1] = ex.expected | 29 | combination[ex.position - 1] = ex.expected | ||
30 | # No exception means that the lock is unlocked | 30 | # No exception means that the lock is unlocked | ||
31 | else: | 31 | else: | ||
32 | break | 32 | break |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
n | n | 1 | class LockPicker_gkunchev: | ||
2 | """Pick a lock. It's that simple!""" | ||||
1 | 3 | ||||
t | 2 | class LockPicker_invalid: | t | 4 | def __init__(self, lock): |
3 | pass | 5 | """Store the lock passed when initializing.""" | ||
6 | self._lock = lock | ||||
7 | |||||
8 | def unlock(self): | ||||
9 | """Try to pick the lock. No - there is no try - PICK THE LOCK!""" | ||||
10 | # Start by passing empty argument list | ||||
11 | # to determine the expected argument count | ||||
12 | combination = [] | ||||
13 | while True: | ||||
14 | try: | ||||
15 | self._lock.pick(*combination) | ||||
16 | except TypeError as ex: | ||||
17 | # This case defines the number of expected arguments | ||||
18 | if ex.position is None: | ||||
19 | # Try with as many None-s as the lock expects as arg count | ||||
20 | combination = [None for _ in range(ex.expected)] | ||||
21 | # This case means the arg count is correct | ||||
22 | # An unexpected type was passed so pass empty instance | ||||
23 | # from the expected type | ||||
24 | else: | ||||
25 | combination[ex.position - 1] = ex.expected() | ||||
26 | # An unexpected value of the correct type was found | ||||
27 | # pass the expected value instead | ||||
28 | except ValueError as ex: | ||||
29 | combination[ex.position - 1] = ex.expected | ||||
30 | # No exception means that the lock is unlocked | ||||
31 | else: | ||||
32 | break |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|