Предизвикателства > Разбий ни ключалката > Решения > Решението на Калоян Марков

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

1 точки общо

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

 1class LockPicker_4MI0600392:
 2    def __init__(self, lock):
 3        self.lock = lock
 4
 5    def unlock(self):
 6        args = []
 7        while True:
 8            try:
 9                self.lock.pick(*args) #Костадин Русалов е гей!(няма да го махна, много е смешно)
10                return  
11            except TypeError as ex:
12                if ex.position is None:
13                    args = [None] * ex.expected
14                else:
15                    expected_type = ex.expected
16                    args[ex.position - 1] = expected_type()
17            except ValueError as ex:
18                args[ex.position - 1] = ex.expected

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

OK

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

f1class LockPicker_4MI0600392:f1class LockPicker_4MI0600392:
2    def __init__(self, lock):2    def __init__(self, lock):
3        self.lock = lock3        self.lock = lock
n4    n4 
5    def unlock(self):5    def unlock(self):
6        args = []6        args = []
7        while True:7        while True:
8            try:8            try:
n9                self.lock.pick(*args) #Костадин Русалов е гей!n9                self.lock.pick(*args) #Костадин Русалов е гей!(няма да го махна, много е смешно)
10                return  10                return  
11            except TypeError as ex:11            except TypeError as ex:
12                if ex.position is None:12                if ex.position is None:
13                    args = [None] * ex.expected13                    args = [None] * ex.expected
14                else:14                else:
t15                    expected_type = ex.expected t15                    expected_type = ex.expected
16                    try:
17                        args[ex.position - 1] = expected_type
18                    except TypeError:
19                        args[ex.position - 1] = expected_type()16                    args[ex.position - 1] = expected_type()
20            except ValueError as ex:17            except ValueError as ex:
21                args[ex.position - 1] = ex.expected18                args[ex.position - 1] = ex.expected
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1class LockPicker_4MI0600392:f1class LockPicker_4MI0600392:
2    def __init__(self, lock):2    def __init__(self, lock):
3        self.lock = lock3        self.lock = lock
4    4    
5    def unlock(self):5    def unlock(self):
6        args = []6        args = []
7        while True:7        while True:
8            try:8            try:
9                self.lock.pick(*args) #Костадин Русалов е гей!9                self.lock.pick(*args) #Костадин Русалов е гей!
10                return  10                return  
11            except TypeError as ex:11            except TypeError as ex:
12                if ex.position is None:12                if ex.position is None:
13                    args = [None] * ex.expected13                    args = [None] * ex.expected
14                else:14                else:
15                    expected_type = ex.expected 15                    expected_type = ex.expected 
16                    try:16                    try:
17                        args[ex.position - 1] = expected_type17                        args[ex.position - 1] = expected_type
18                    except TypeError:18                    except TypeError:
19                        args[ex.position - 1] = expected_type()19                        args[ex.position - 1] = expected_type()
20            except ValueError as ex:20            except ValueError as ex:
21                args[ex.position - 1] = ex.expected21                args[ex.position - 1] = ex.expected
t22 t
23 
24                
25            
26 
27 
28            
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op