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

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

1 точки общо

1 успешни теста
0 неуспешни теста
Код (changed method to getattr())

 1def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name):
 2    class Mixin:
 3        def is_a_witch(self):
 4            if hasattr(self, mass_attr_name) and getattr(self,mass_attr_name) == mass:
 5                return "Burn her!"
 6            elif hasattr(self, material_attr_name) and getattr(self, material_attr_name) == material:
 7                return "Burn her!"
 8            elif hasattr(self, float_method_name) and callable(getattr(self, float_method_name)):
 9                return "Burn her!"
10            else:
11                return "No, but it's a pity, cuz she looks like a witch!"
12    return Mixin

.
----------------------------------------------------------------------
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):
n2    class Mixin():n2    class Mixin:
3        def is_a_witch(self):3        def is_a_witch(self):
n4            if hasattr(self, mass_attr_name) and self.__getattribute__(mass_attr_name) == mass:n4            if hasattr(self, mass_attr_name) and getattr(self,mass_attr_name) == mass:
5                return "Burn her!"5                return "Burn her!"
n6            elif hasattr(self, material_attr_name) and self.__getattribute__(material_attr_name) == material:n6            elif hasattr(self, material_attr_name) and getattr(self, material_attr_name) == material:
7                return "Burn her!"7                return "Burn her!"
n8            elif hasattr(self, float_method_name) and callable(self.__getattribute__(float_method_name)):n8            elif hasattr(self, float_method_name) and callable(getattr(self, float_method_name)):
9                return "Burn her!"9                return "Burn her!"
10            else:10            else:
11                return "No, but it's a pity, cuz she looks like a witch!"11                return "No, but it's a pity, cuz she looks like a witch!"
12    return Mixin12    return Mixin
t13 t
14 
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):
2    class Mixin():2    class Mixin():
3        def is_a_witch(self):3        def is_a_witch(self):
n4            if hasattr(self,mass_attr_name) and self.__getattribute__(mass_attr_name) == mass:n4            if hasattr(self, mass_attr_name) and self.__getattribute__(mass_attr_name) == mass:
5                return "Burn her!"5                return "Burn her!"
n6            elif hasattr(self,material_attr_name) and self.__getattribute__(material_attr_name) == material:n6            elif hasattr(self, material_attr_name) and self.__getattribute__(material_attr_name) == material:
7                return "Burn her!"7                return "Burn her!"
t8            elif hasattr(self,float_method_name) and callable(self.__getattribute__(float_method_name)):t8            elif hasattr(self, float_method_name) and callable(self.__getattribute__(float_method_name)):
9                return "Burn her!"9                return "Burn her!"
10            else:10            else:
11                return "No, but it's a pity, cuz she looks like a witch!"11                return "No, but it's a pity, cuz she looks like a witch!"
12    return Mixin12    return Mixin
1313
1414
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op