Предизвикателства > Сляпа баба > Решения > Решението на Даниел Йорданов

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

1 точки общо

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

 1import secret
 2
 3def recursiveSearch(collection_interesting, collection_to_search_into, collection_parents):
 4    if len(collection_to_search_into) == 0:
 5        return
 6    for s in collection_to_search_into:
 7        for el in dir(s):
 8            if len(el) == 1 and callable(getattr(s, el)):
 9                collection_interesting.append(getattr(s, el))
10                collection_parents.append(s)
11            if 'clue' in el:
12                collection_to_search_into.append(getattr(s, el))
13        collection_to_search_into.remove(s)
14    recursiveSearch(collection_interesting, collection_to_search_into, collection_parents)
15 
16def methodify():
17    #set the almost interesting objects
18    collection_to_search = list()
19    collection_to_search.append(secret)
20    collection_interesting_global = []
21    collection_parents_global = []
22
23    recursiveSearch(collection_interesting_global, collection_to_search, collection_parents_global)
24
25    def check_static_function(func, parent):
26        if(parent.__class__ is not type(type)):
27            return hasattr(parent.__class__, func.__name__)
28        return True
29
30    #set the actual interesting objects
31    collection_interesting_functions = []
32    for index_el in range(len(collection_interesting_global)):
33        #5th condition
34        if check_static_function(collection_interesting_global[index_el], collection_parents_global[index_el]):
35            collection_interesting_functions.append(collection_interesting_global[index_el])
36            continue
37        #4th condition
38        try:
39            if collection_interesting_global(left = "leftSide", right = "rightSide") == "leftSideRightSide":
40               collection_interesting_functions.append(collection_interesting_global[index_el])
41               continue
42        except:
43            pass
44        #3rd condition
45        try:
46            if collection_interesting_global[index_el](10) == 100 and collection_interesting_global[index_el](9) == 0:
47                collection_interesting_functions.append(collection_interesting_global[index_el])
48                continue
49        except:
50            pass
51        #1st condition
52        try:
53            collection_interesting_global[index_el]()
54        except TypeError as err:
55            if str(err) == "Опаааааа, тука има нещо нередно.":
56                collection_interesting_functions.append(collection_interesting_global[index_el])
57                continue
58        #2nd condition
59        try:
60            collection_interesting_global[index_el]()
61        except BaseException:
62            collection_interesting_functions.append(collection_interesting_global[index_el])
63            continue
64
65    FACULTY_NUMBER = 'FN3MI0600149'
66
67    functions_from_fn = []
68    for symbol in FACULTY_NUMBER:
69        found = False
70        for func in collection_interesting_functions:
71            if(func.__name__ == symbol):
72                functions_from_fn.append(func)
73                found = True
74                break
75        if not found:
76            return None
77    return tuple(functions_from_fn)

E
======================================================================
ERROR: test_metodify (test.TestMethodify)
Test metodify function.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 12, in test_metodify
self.assertIn(methodify(), _RESULTS.keys())
File "/tmp/solution.py", line 53, in methodify
collection_interesting_global[index_el]()
File "/tmp/secret.py", line 11, in method_N
raise BaseException('Опаааааа, и тука има нещо нередно.')
BaseException: Опаааааа, и тука има нещо нередно.

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

FAILED (errors=1)

Дискусия
История
Това решение има само една версия.