Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- class BellTower:
- def __init__(self, *args):
- self.bells = []
- for arg in args:
- self.bells.append(arg)
- def append(self, bell):
- self.bells.append(bell)
- def sound(self):
- for bell in self.bells:
- bell.sound()
- print('...')
- def print_info(self):
- counter = 0
- for bell in self.bells[::-1]:
- counter += 1
- print(counter, bell.print_info())
- class LittleBell():
- def __init__(self, *args, **kwargs):
- self.args = args
- self.kwargs = kwargs
- def sound(self):
- print("ding")
- def print_info(self):
- result = json.dumps(self.kwargs, ensure_ascii=False).replace("{", "").replace("}", "").replace('"', "")
- if self.kwargs and self.args:
- result += " ; "
- result += " ".join(self.args)
- return result
- return " ".join(self.args)
- class BigBell():
- a = True
- def __init__(self, *args, **kwargs):
- self.args = args
- self.kwargs = kwargs
- def sound(self):
- print('ding' if self.a else 'dong')
- self.a = not self.a
- def print_info(self):
- result = json.dumps(self.kwargs, ensure_ascii=False).replace("{", "").replace("}", "").replace('"', "")
- if self.kwargs and self.args:
- result += "; "
- result += " ".join(self.args)
- return result
- return " ".join(self.args)
- class SizedBellTower(BellTower):
- def __init__(self, size=10, *args):
- self.size = size
- self.bells = []
- for arg in args:
- self.bells.append(arg)
- if len(self.bells) > self.size:
- self.bells.pop(0)
- def append(self, bell):
- self.bells.append(bell)
- if len(self.bells) > self.size:
- self.bells.pop(0)
- class TypedBellTower(BellTower):
- def __init__(self, bell_type=LittleBell, *args):
- self.bells = []
- for arg in args:
- if arg is bell_type:
- self.bells.append(arg)
- bt = BellTower(BigBell("бронзовый"),
- LittleBell("медный", нота="ля"))
- bt.append(BigBell(название="Корноухий", вес="1275 пудов"))
- bt.print_info()
- bt.sound()
- bt.sound()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement