Advertisement
WupEly

Untitled

Oct 27th, 2022
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. import json
  2.  
  3. class BellTower:
  4.  
  5. def __init__(self, *args):
  6. self.bells = []
  7. for arg in args:
  8. self.bells.append(arg)
  9.  
  10. def append(self, bell):
  11. self.bells.append(bell)
  12.  
  13. def sound(self):
  14. for bell in self.bells:
  15. bell.sound()
  16. print('...')
  17.  
  18. def print_info(self):
  19. counter = 0
  20. for bell in self.bells[::-1]:
  21. counter += 1
  22. print(counter, bell.print_info())
  23.  
  24.  
  25. class LittleBell():
  26.  
  27. def __init__(self, *args, **kwargs):
  28. self.args = args
  29. self.kwargs = kwargs
  30.  
  31. def sound(self):
  32. print("ding")
  33.  
  34. def print_info(self):
  35. result = json.dumps(self.kwargs, ensure_ascii=False).replace("{", "").replace("}", "").replace('"', "")
  36. if self.kwargs and self.args:
  37. result += " ; "
  38. result += " ".join(self.args)
  39. return result
  40. return " ".join(self.args)
  41.  
  42. class BigBell():
  43. a = True
  44.  
  45. def __init__(self, *args, **kwargs):
  46. self.args = args
  47. self.kwargs = kwargs
  48.  
  49. def sound(self):
  50. print('ding' if self.a else 'dong')
  51. self.a = not self.a
  52.  
  53. def print_info(self):
  54. result = json.dumps(self.kwargs, ensure_ascii=False).replace("{", "").replace("}", "").replace('"', "")
  55. if self.kwargs and self.args:
  56. result += "; "
  57. result += " ".join(self.args)
  58. return result
  59. return " ".join(self.args)
  60.  
  61.  
  62.  
  63. class SizedBellTower(BellTower):
  64.  
  65. def __init__(self, size=10, *args):
  66. self.size = size
  67. self.bells = []
  68. for arg in args:
  69. self.bells.append(arg)
  70. if len(self.bells) > self.size:
  71. self.bells.pop(0)
  72.  
  73. def append(self, bell):
  74. self.bells.append(bell)
  75. if len(self.bells) > self.size:
  76. self.bells.pop(0)
  77.  
  78.  
  79. class TypedBellTower(BellTower):
  80.  
  81. def __init__(self, bell_type=LittleBell, *args):
  82. self.bells = []
  83. for arg in args:
  84. if arg is bell_type:
  85. self.bells.append(arg)
  86.  
  87.  
  88.  
  89.  
  90. bt = BellTower(BigBell("бронзовый"),
  91. LittleBell("медный", нота="ля"))
  92. bt.append(BigBell(название="Корноухий", вес="1275 пудов"))
  93. bt.print_info()
  94. bt.sound()
  95. bt.sound()
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement