Предизвикателства > Разбий ни ключалката > Решения > Решението на Димитър Танков

Резултати
1 точки от тестове
0 точки от учител

1 точки общо

1 успешни теста
0 неуспешни теста
Код

 1class LockPicker_2MI0600229:
 2    def __init__(self, lock):
 3        self.lock = lock
 4
 5    def unlock(self):
 6        args = []
 7
 8        while True:
 9            try:
10                if self.lock.pick(*args):
11                    return
12
13            except TypeError as exception:
14                if exception.position is None:
15                    args = [0] * exception.expected
16                else:
17                    args[exception.position - 1] = exception.expected()
18
19            except ValueError as exception:
20                args[exception.position - 1] = exception.expected

Резултат от контролното:
23/25 верни отговора.
19 точки.
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

Дискусия
История

f1class LockPicker_2MI0600229:f1class LockPicker_2MI0600229:
2    def __init__(self, lock):2    def __init__(self, lock):
3        self.lock = lock3        self.lock = lock
44
5    def unlock(self):5    def unlock(self):
6        args = []6        args = []
77
8        while True:8        while True:
t9            print(args)t
10            try:9            try:
11                if self.lock.pick(*args):10                if self.lock.pick(*args):
12                    return11                    return
1312
14            except TypeError as exception:13            except TypeError as exception:
15                if exception.position is None:14                if exception.position is None:
16                    args = [0] * exception.expected15                    args = [0] * exception.expected
17                else:16                else:
18                    args[exception.position - 1] = exception.expected()17                    args[exception.position - 1] = exception.expected()
1918
20            except ValueError as exception:19            except ValueError as exception:
21                args[exception.position - 1] = exception.expected20                args[exception.position - 1] = exception.expected
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1class LockPicker_2MI0600229:f1class LockPicker_2MI0600229:
2    def __init__(self, lock):2    def __init__(self, lock):
3        self.lock = lock3        self.lock = lock
44
5    def unlock(self):5    def unlock(self):
6        args = []6        args = []
77
8        while True:8        while True:
9            print(args)9            print(args)
10            try:10            try:
11                if self.lock.pick(*args):11                if self.lock.pick(*args):
t12                    print("les get")t
13                    return12                    return
1413
15            except TypeError as exception:14            except TypeError as exception:
16                if exception.position is None:15                if exception.position is None:
17                    args = [0] * exception.expected16                    args = [0] * exception.expected
18                else:17                else:
19                    args[exception.position - 1] = exception.expected()18                    args[exception.position - 1] = exception.expected()
2019
21            except ValueError as exception:20            except ValueError as exception:
22                args[exception.position - 1] = exception.expected21                args[exception.position - 1] = exception.expected
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op