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

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

1 точки общо

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

 1class HauntedMansion:
 2    __prefix = "spooky_"
 3
 4    def __init__(self, **kwargs):
 5        for key, value in kwargs.items():
 6            setattr(self, key, value)
 7
 8    def __getattr__(self, name):
 9            return "Booooo, only ghosts here!"
10        
11    def __setattr__(self, name, value):
12        super().__setattr__(f"{self.__prefix}{name}", value)

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

OK

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

f1class HauntedMansion:f1class HauntedMansion:
2    __prefix = "spooky_"2    __prefix = "spooky_"
33
4    def __init__(self, **kwargs):4    def __init__(self, **kwargs):
5        for key, value in kwargs.items():5        for key, value in kwargs.items():
6            setattr(self, key, value)6            setattr(self, key, value)
77
8    def __getattr__(self, name):8    def __getattr__(self, name):
n9        #if not name.startswith(self.__prefix) and not name.startswith("__"):n
10            return "Booooo, only ghosts here!"9            return "Booooo, only ghosts here!"
11        10        
12    def __setattr__(self, name, value):11    def __setattr__(self, name, value):
13        super().__setattr__(f"{self.__prefix}{name}", value)12        super().__setattr__(f"{self.__prefix}{name}", value)
tt13 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1class HauntedMansion:f1class HauntedMansion:
2    __prefix = "spooky_"2    __prefix = "spooky_"
33
4    def __init__(self, **kwargs):4    def __init__(self, **kwargs):
5        for key, value in kwargs.items():5        for key, value in kwargs.items():
6            setattr(self, key, value)6            setattr(self, key, value)
77
8    def __getattr__(self, name):8    def __getattr__(self, name):
n9        if not name.startswith(self.__prefix) and not name.startswith("__"):n9        #if not name.startswith(self.__prefix) and not name.startswith("__"):
10            return "Booooo, only ghosts here!"10            return "Booooo, only ghosts here!"
11        11        
12    def __setattr__(self, name, value):12    def __setattr__(self, name, value):
13        super().__setattr__(f"{self.__prefix}{name}", value)13        super().__setattr__(f"{self.__prefix}{name}", value)
t14 t
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1class HauntedMansion:f1class HauntedMansion:
2    __prefix = "spooky_"2    __prefix = "spooky_"
33
4    def __init__(self, **kwargs):4    def __init__(self, **kwargs):
5        for key, value in kwargs.items():5        for key, value in kwargs.items():
6            setattr(self, key, value)6            setattr(self, key, value)
77
8    def __getattr__(self, name):8    def __getattr__(self, name):
9        if not name.startswith(self.__prefix) and not name.startswith("__"):9        if not name.startswith(self.__prefix) and not name.startswith("__"):
10            return "Booooo, only ghosts here!"10            return "Booooo, only ghosts here!"
11        11        
t12        t
13    def __setattr__(self, name, value):12    def __setattr__(self, name, value):
14        super().__setattr__(f"{self.__prefix}{name}", value)13        super().__setattr__(f"{self.__prefix}{name}", value)
1514
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op