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

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

0 точки общо

0 успешни теста
1 неуспешни теста
Код
Скрий всички коментари

 1class LockPicker_1MI0600289():
 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                #no error was raised
11                break
12            except TypeError as exc:
13                if exc.position is None:
14                    #needs to expand
15                    while len(*args) < exc.expected:
16                        args.append(None)
17                else:
18                    #change type
19                    args[exc.position - 1] = exc.expected(args[exc.position - 1])
20            except ValueError as exc:
21                #change element
22                args[exc.position - 1] = exc.expected
23        
24                

Грешка при опит за отключване:
Traceback (most recent call last):
File "/tmp/solution.py", line 9, in unlock
self.lock.pick(*args)
File "/tmp/test.py", line 50, in pick
raise LockTypeError("This is a different kind of lock.",
test.LockTypeError: This is a different kind of lock.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/tmp/test.py", line 98, in <module>
test_unlocker(LockPicker(lock))
File "/usr/local/lib/python3.12/dist-packages/timeout_decorator/timeout_decorator.py", line 82, in new_function
return function(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/test.py", line 77, in test_unlocker
unlocker.unlock()
File "/tmp/solution.py", line 15, in unlock
while len(*args) < exc.expected:
^^^^^^^^^^
TypeError: len() takes exactly one argument (0 given)

F
======================================================================
FAIL: test_picking (test.TestLockPicker.test_picking)
Ensure the lock is picked based on already stored boolean var.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 72, in test_picking
self.assertTrue(correct, "Не успя да отключиш.")
AssertionError: False is not true : Не успя да отключиш.

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (failures=1)

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

f1class LockPicker_1MI0600289():f1class LockPicker_1MI0600289():
2    def __init__(self, lock):2    def __init__(self, lock):
3        self.lock = lock  3        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                #no error was raised10                #no error was raised
11                break11                break
12            except TypeError as exc:12            except TypeError as exc:
13                if exc.position is None:13                if exc.position is None:
14                    #needs to expand14                    #needs to expand
t15                    if len(*args) < exc.expected:t15                    while len(*args) < exc.expected:
16                        args.append(0)16                        args.append(None)
17                else:17                else:
18                    #change type18                    #change type
19                    args[exc.position - 1] = exc.expected(args[exc.position - 1])19                    args[exc.position - 1] = exc.expected(args[exc.position - 1])
20            except ValueError as exc:20            except ValueError as exc:
21                #change element21                #change element
22                args[exc.position - 1] = exc.expected22                args[exc.position - 1] = exc.expected
23        23        
24                24                
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1class LockPicker_1MI0600289():f1class LockPicker_1MI0600289():
2    def __init__(self, lock):2    def __init__(self, lock):
3        self.lock = lock  3        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                #no error was raised10                #no error was raised
11                break11                break
12            except TypeError as exc:12            except TypeError as exc:
13                if exc.position is None:13                if exc.position is None:
14                    #needs to expand14                    #needs to expand
15                    if len(*args) < exc.expected:15                    if len(*args) < exc.expected:
16                        args.append(0)16                        args.append(0)
t17                    #needs to shrimt
18                    else:
19                        args = args[:exc.position + 1] 
20                else:17                else:
21                    #change type18                    #change type
22                    args[exc.position - 1] = exc.expected(args[exc.position - 1])19                    args[exc.position - 1] = exc.expected(args[exc.position - 1])
23            except ValueError as exc:20            except ValueError as exc:
24                #change element21                #change element
25                args[exc.position - 1] = exc.expected22                args[exc.position - 1] = exc.expected
26        23        
27                24                
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1class LockPicker_1MI0600289():f1class LockPicker_1MI0600289():
2    def __init__(self, lock):2    def __init__(self, lock):
3        self.lock = lock  3        self.lock = lock  
4   4   
t5    def unlock(self, *args):t5    def unlock(self):
6        args = []
6        while True:7        while True:
7            try:8            try:
8                self.lock.pick(*args)9                self.lock.pick(*args)
9                #no error was raised10                #no error was raised
10                break11                break
11            except TypeError as exc:12            except TypeError as exc:
12                if exc.position is None:13                if exc.position is None:
13                    #needs to expand14                    #needs to expand
14                    if len(*args) < exc.expected:15                    if len(*args) < exc.expected:
15                        args.append(0)16                        args.append(0)
16                    #needs to shrim17                    #needs to shrim
17                    else:18                    else:
18                        args = args[:exc.position + 1] 19                        args = args[:exc.position + 1] 
19                else:20                else:
20                    #change type21                    #change type
21                    args[exc.position - 1] = exc.expected(args[exc.position - 1])22                    args[exc.position - 1] = exc.expected(args[exc.position - 1])
22            except ValueError as exc:23            except ValueError as exc:
23                #change element24                #change element
24                args[exc.position - 1] = exc.expected25                args[exc.position - 1] = exc.expected
25        26        
26                27                
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

t1class LockPicker_FN1MI0600289():t1class LockPicker_1MI0600289():
2    def __init__(self, lock):2    def __init__(self, lock):
3        self.lock = lock  3        self.lock = lock  
4   4   
5    def unlock(self, *args):5    def unlock(self, *args):
6        while True:6        while True:
7            try:7            try:
8                self.lock.pick(*args)8                self.lock.pick(*args)
9                #no error was raised9                #no error was raised
10                break10                break
11            except TypeError as exc:11            except TypeError as exc:
12                if exc.position is None:12                if exc.position is None:
13                    #needs to expand13                    #needs to expand
14                    if len(*args) < exc.expected:14                    if len(*args) < exc.expected:
15                        args.append(0)15                        args.append(0)
16                    #needs to shrim16                    #needs to shrim
17                    else:17                    else:
18                        args = args[:exc.position + 1] 18                        args = args[:exc.position + 1] 
19                else:19                else:
20                    #change type20                    #change type
21                    args[exc.position - 1] = exc.expected(args[exc.position - 1])21                    args[exc.position - 1] = exc.expected(args[exc.position - 1])
22            except ValueError as exc:22            except ValueError as exc:
23                #change element23                #change element
24                args[exc.position - 1] = exc.expected24                args[exc.position - 1] = exc.expected
25        25        
26                26                
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op