1class HauntedMansion:
2 """
3 A class representing a haunted mansion where every room is a chilling
4 reminder of why you should never assign too much homework. Expect
5 ghostly residents eager to remind you that even they know how to
6 procrastinate!
7 """
8
9 def __init__(self, **kwargs):
10 """
11 Initialize the haunted mansion with various attributes.
12 Add your ghostly touches using keyword arguments because nothing
13 says 'home sweet home' like an excessive amount of unfinished homework.
14
15 Example:
16 >>> mansion = HauntedMansion(candles=5, ghosts=3)
17 >>> mansion.spooky_candles
18 5
19 """
20 for key, value in kwargs.items():
21 self.__setattr__(key, value)
22
23 def __setattr__(self, name, value):
24 """
25 Set an attribute in the haunted mansion, but beware:
26 it will always be prefixed with 'spooky_' because 'normal'
27 is reserved for teachers who don't assign homework over the weekend.
28
29 Parameters:
30 name (str): The name of the attribute to set.
31 value: The value to assign to the spooky attribute.
32 """
33 return super().__setattr__("spooky_" + name, value)
34
35 def __getattr__(self, name):
36 """
37 Get an attribute from the haunted mansion.
38 If the attribute doesn't exist, brace yourself for a scare!
39 The only thing lurking in the shadows is a ghostly reminder
40 that you should have turned in that paper.
41
42 Parameters:
43 name (str): The name of the attribute to retrieve.
44
45 Returns:
46 str: A spooky message indicating the absence of the requested attribute.
47 """
48 return "Booooo, only ghosts here!"
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
Никола Георгиев
03.11.2024 07:57Благодаря :))
|
Виктор Бечев
02.11.2024 20:43Хахаха, докстринговете са оценени, по решението - нямам нищо. :grin:
|