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

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

1 точки общо

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

 1def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name):
 2
 3
 4    class LogicMixin:
 5        def __init__(self, mass, mass_attr_name, material, material_attr_name, float_method_name):
 6            setattr(self, mass_attr_name, mass)
 7            setattr(self, material_attr_name, material)
 8            setattr(self, float_method_name, lambda: None)
 9
10        def is_a_witch(self):
11            if hasattr(self, mass_attr_name) and getattr(self, mass_attr_name) == mass:
12                return "Burn her!"
13            elif hasattr(self, material_attr_name) and getattr(self, material_attr_name) == material:
14                return "Burn her!"
15            elif hasattr(self, float_method_name) and callable(getattr(self, float_method_name)):
16                return "Burn her!"
17            else:
18                return "No, but it's a pity, cuz she looks like a witch!"
19            
20        
21    return LogicMixin

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

OK

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

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):
22
33
4    class LogicMixin:4    class LogicMixin:
5        def __init__(self, mass, mass_attr_name, material, material_attr_name, float_method_name):5        def __init__(self, mass, mass_attr_name, material, material_attr_name, float_method_name):
n6            self.float_method_name = float_method_namen
7            setattr(self, mass_attr_name, mass)6            setattr(self, mass_attr_name, mass)
8            setattr(self, material_attr_name, material)7            setattr(self, material_attr_name, material)
nn8            setattr(self, float_method_name, lambda: None)
99
10        def is_a_witch(self):10        def is_a_witch(self):
11            if hasattr(self, mass_attr_name) and getattr(self, mass_attr_name) == mass:11            if hasattr(self, mass_attr_name) and getattr(self, mass_attr_name) == mass:
12                return "Burn her!"12                return "Burn her!"
13            elif hasattr(self, material_attr_name) and getattr(self, material_attr_name) == material:13            elif hasattr(self, material_attr_name) and getattr(self, material_attr_name) == material:
14                return "Burn her!"14                return "Burn her!"
15            elif hasattr(self, float_method_name) and callable(getattr(self, float_method_name)):15            elif hasattr(self, float_method_name) and callable(getattr(self, float_method_name)):
16                return "Burn her!"16                return "Burn her!"
17            else:17            else:
18                return "No, but it's a pity, cuz she looks like a witch!"18                return "No, but it's a pity, cuz she looks like a witch!"
19            19            
20        20        
21    return LogicMixin21    return LogicMixin
t22 t
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op