Предизвикателства > She's a witch! > Решения > Решението на Михаил Цанков

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

0 точки общо

0 успешни теста
1 неуспешни теста
Код (using the fancy animal namedtuple)

 1from collections import namedtuple
 2
 3
 4def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name):
 5
 6    Birthmark = namedtuple('Birthmark', ['key', 'value'], defaults=('', None))
 7
 8    witch_birthmarks = [
 9        Birthmark(mass_attr_name, mass),
10        Birthmark(material_attr_name, material),
11        Birthmark(float_method_name)
12    ]
13
14    class LogicMixin:
15        def is_a_witch(self):
16            attributes = dir(self)
17            for birthmark in witch_birthmarks:
18                if birthmark.key not in attributes:
19                    continue
20
21                if not birthmark.value or getattr(self, birthmark.key) == birthmark.value:
22                    return "Burn her!"
23
24            return "No, but it's a pity, cuz she looks like a witch!"
25
26    return LogicMixin

F
======================================================================
FAIL: test_realcase (test.TestWitchMixinFactory)
Real test for the Witch factory.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 50, in test_realcase
self.assertEqual(FloatFalse().is_a_witch(), self.RESULT_FALSE)
AssertionError: 'Burn her!' != "No, but it's a pity, cuz she looks like a witch!"
- Burn her!
+ No, but it's a pity, cuz she looks like a witch!

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (failures=1)

Дискусия
Михаил Цанков
08.11.2023 21:30

Не ще кача вярно решение по-късно. Засега заявявам че всички жени са вещици!
Георги Кунчев
08.11.2023 21:06

Не съм сигурен дали само заявяваш присъствие, или залагаш, че ако имаме два теста и единият ти мине, ще закръглим нагоре и ще вземеш точката :smile:
История

nn1from collections import namedtuple
2 
3 
1def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name):4def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name):
t2    class Birthmark:t5 
3        def __init__(self, key, value=None):6    Birthmark = namedtuple('Birthmark', ['key', 'value'], defaults=('', None))
4            self.key = key
5            self.value = value
67
7    witch_birthmarks = [8    witch_birthmarks = [
8        Birthmark(mass_attr_name, mass),9        Birthmark(mass_attr_name, mass),
9        Birthmark(material_attr_name, material),10        Birthmark(material_attr_name, material),
10        Birthmark(float_method_name)11        Birthmark(float_method_name)
11    ]12    ]
1213
13    class LogicMixin:14    class LogicMixin:
14        def is_a_witch(self):15        def is_a_witch(self):
15            attributes = dir(self)16            attributes = dir(self)
16            for birthmark in witch_birthmarks:17            for birthmark in witch_birthmarks:
17                if birthmark.key not in attributes:18                if birthmark.key not in attributes:
18                    continue19                    continue
1920
20                if not birthmark.value or getattr(self, birthmark.key) == birthmark.value:21                if not birthmark.value or getattr(self, birthmark.key) == birthmark.value:
21                    return "Burn her!"22                    return "Burn her!"
2223
23            return "No, but it's a pity, cuz she looks like a witch!"24            return "No, but it's a pity, cuz she looks like a witch!"
2425
25    return LogicMixin26    return LogicMixin
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name):f1def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name):
nn2    class Birthmark:
3        def __init__(self, key, value=None):
4            self.key = key
5            self.value = value
6 
7    witch_birthmarks = [
8        Birthmark(mass_attr_name, mass),
9        Birthmark(material_attr_name, material),
10        Birthmark(float_method_name)
11    ]
12 
2    class LogicMixin:13    class LogicMixin:
t3        def is_a_witch():t14        def is_a_witch(self):
15            attributes = dir(self)
16            for birthmark in witch_birthmarks:
17                if birthmark.key not in attributes:
18                    continue
19 
20                if not birthmark.value or getattr(self, birthmark.key) == birthmark.value:
4            return "Burn her!"21                    return "Burn her!"
22 
23            return "No, but it's a pity, cuz she looks like a witch!"
524
6    return LogicMixin25    return LogicMixin
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op