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

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

0 точки общо

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

 1python = """
 2         /^\\/^\\
 3       _|__|  O|
 4\\/     /~     \\_/ \\
 5 \\____|__________/  \\
 6        \\_______      \\
 7                `\\     \\                 \\
 8                  |     |                  \\
 9                 /      /                    \\
10                /     /                       \\\\
11              /      /                         \\ \\
12             /     /                            \\  \\
13           /     /             _----_            \\   \\
14          /     /           _-~      ~-_         |   |
15         (      (        _-~    _--_    ~-_     _/   |
16          \\      ~-____-~    _-~    ~-_    ~-_-~    /
17            ~-_           _-~          ~-_       _-~  
18               ~--______-~                ~-___-~    
19"""
20
21
22class LockPicker_0MI0600371: #<-къде ми е змията?
23   
24    def __init__(self, lock):
25        self.lock = lock
26        self.combinations = []
27
28    def unlock(self):
29        picked = False
30        while picked:
31            try:
32                picked = self.lock.pick(*self.combinations)
33            except Exception as exp:
34                if type(exp) is TypeError:
35                    if exp.position is None:
36                        self.combinations.clear() #precaution
37                        while exp.expected > len(self.combinations):
38                            self.combinations.insert(None)
39                    else:
40                        self.combinations[exp.position-1] = exp.expected()
41                elif type(exp) is ValueError:
42                    self.args[exp.position - 1] = exp.expected
43                else:
44                    self.pray_to_the_python(python)
45
46    def pray_to_the_python(self):
47        print("Praise be to the Python!(only he can save us)")
48        print(python)
49        print("Praise be to the Python!(I'm starting to think he's clueless too)")
50        return

Неуспешно отключване.
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)

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

f1python = """f1python = """
2         /^\\/^\\2         /^\\/^\\
3       _|__|  O|3       _|__|  O|
4\\/     /~     \\_/ \\4\\/     /~     \\_/ \\
5 \\____|__________/  \\5 \\____|__________/  \\
6        \\_______      \\6        \\_______      \\
7                `\\     \\                 \\7                `\\     \\                 \\
8                  |     |                  \\8                  |     |                  \\
9                 /      /                    \\9                 /      /                    \\
10                /     /                       \\\\10                /     /                       \\\\
11              /      /                         \\ \\11              /      /                         \\ \\
12             /     /                            \\  \\12             /     /                            \\  \\
13           /     /             _----_            \\   \\13           /     /             _----_            \\   \\
14          /     /           _-~      ~-_         |   |14          /     /           _-~      ~-_         |   |
15         (      (        _-~    _--_    ~-_     _/   |15         (      (        _-~    _--_    ~-_     _/   |
16          \\      ~-____-~    _-~    ~-_    ~-_-~    /16          \\      ~-____-~    _-~    ~-_    ~-_-~    /
17            ~-_           _-~          ~-_       _-~  17            ~-_           _-~          ~-_       _-~  
18               ~--______-~                ~-___-~    18               ~--______-~                ~-___-~    
19"""19"""
2020
2121
22class LockPicker_0MI0600371: #<-къде ми е змията?22class LockPicker_0MI0600371: #<-къде ми е змията?
23   23   
24    def __init__(self, lock):24    def __init__(self, lock):
25        self.lock = lock25        self.lock = lock
26        self.combinations = []26        self.combinations = []
2727
28    def unlock(self):28    def unlock(self):
29        picked = False29        picked = False
30        while picked:30        while picked:
31            try:31            try:
32                picked = self.lock.pick(*self.combinations)32                picked = self.lock.pick(*self.combinations)
33            except Exception as exp:33            except Exception as exp:
34                if type(exp) is TypeError:34                if type(exp) is TypeError:
35                    if exp.position is None:35                    if exp.position is None:
36                        self.combinations.clear() #precaution36                        self.combinations.clear() #precaution
37                        while exp.expected > len(self.combinations):37                        while exp.expected > len(self.combinations):
38                            self.combinations.insert(None)38                            self.combinations.insert(None)
39                    else:39                    else:
t40                        self.combinations[exp.position-1] = exp.expected(0)t40                        self.combinations[exp.position-1] = exp.expected()
41                elif type(exp) is ValueError:41                elif type(exp) is ValueError:
42                    self.args[exp.position - 1] = exp.expected42                    self.args[exp.position - 1] = exp.expected
43                else:43                else:
44                    self.pray_to_the_python(python)44                    self.pray_to_the_python(python)
4545
46    def pray_to_the_python(self):46    def pray_to_the_python(self):
47        print("Praise be to the Python!(only he can save us)")47        print("Praise be to the Python!(only he can save us)")
48        print(python)48        print(python)
49        print("Praise be to the Python!(I'm starting to think he's clueless too)")49        print("Praise be to the Python!(I'm starting to think he's clueless too)")
50        return50        return
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op