Предизвикателства > Haunted mansion > Решения > Решението на Даниел Манчевски

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

0 точки общо

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

 1class HauntedMansion:
 2    def __init__(self, **kwagrs):
 3        for dark in kwagrs:
 4            object.__setattr__(self, dark, kwagrs[dark])
 5
 6    def __setattr__(self, name, value):
 7        object.__setattr__(self, name, value)
 8
 9    def __getattribute__(self, name):
10        if name.startswith("__"):
11            return object.__getattribute__(self, name)
12        elif name.startswith("spooky_"):
13            name = name.removeprefix("spooky_")
14            return object.__getattribute__(self, name)
15        else:
16            return "Booooo, only ghosts here!"

E
======================================================================
ERROR: test_haunted_mansion (test.TestHauntedMansion.test_haunted_mansion)
The mansion should be really spooky and haunted.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 25, in test_haunted_mansion
self.assertEqual(haunted_mansion.spooky_buttler, "Booooo, only ghosts here!")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 14, in __getattribute__
return object.__getattribute__(self, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'HauntedMansion' object has no attribute 'buttler'

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

FAILED (errors=1)

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