| f | class Currency: | f | class Currency: |
| def __init__(self, name, amount_per_vote): | | def __init__(self, name, amount_per_vote): |
| self.name = name | | self.name = name |
| self.amount_per_vote = amount_per_vote | | self.amount_per_vote = amount_per_vote |
| | | |
| def __eq__(self, other): | | def __eq__(self, other): |
| if not isinstance(other, Currency): | | if not isinstance(other, Currency): |
| return False | | return False |
| return self.name == other.name and self.amount_per_vote == other.amount_per_vote | | return self.name == other.name and self.amount_per_vote == other.amount_per_vote |
| | | |
| class PoliticalParty: | | class PoliticalParty: |
| def __init__(self, name, motto, members=[], preferred_currency=None): | | def __init__(self, name, motto, members=[], preferred_currency=None): |
| self.name = name | | self.name = name |
| self.__motto = motto | | self.__motto = motto |
| self.members = members | | self.members = members |
| self.preferred_currency = preferred_currency | | self.preferred_currency = preferred_currency |
| | | |
| @property | | @property |
| def motto(self): | | def motto(self): |
| return self.__motto | | return self.__motto |
| | | |
| def convert_currency_to_voters(self, amount, currency): | | def convert_currency_to_voters(self, amount, currency): |
| votes = int(amount / currency.amount_per_vote) | | votes = int(amount / currency.amount_per_vote) |
| if currency == self.preferred_currency: | | if currency == self.preferred_currency: |
| return votes * 2 | | return votes * 2 |
| return votes | | return votes |
| | | |
| def __str__(self): | | def __str__(self): |
| return self.name | | return self.name |
| | | |
| def __add__(self, other): | | def __add__(self, other): |
| return Coalition(self, other) | | return Coalition(self, other) |
| | | |
| class Coalition: | | class Coalition: |
| def __init__(self, *political_parties): | | def __init__(self, *political_parties): |
| self.political_parties = list(political_parties) | | self.political_parties = list(political_parties) |
| | | |
| @property | | @property |
| def members(self): | | def members(self): |
| return {party.name: party.members for party in self.political_parties} | | return {party.name: party.members for party in self.political_parties} |
| | | |
| def __add__(self, other): | | def __add__(self, other): |
| if isinstance(other, PoliticalParty): | | if isinstance(other, PoliticalParty): |
| return Coalition(*self.political_parties, other) | | return Coalition(*self.political_parties, other) |
| if isinstance(other, Coalition): | | if isinstance(other, Coalition): |
| return Coalition(*self.political_parties, *other.political_parties) | | return Coalition(*self.political_parties, *other.political_parties) |
| | | |
| def __str__(self): | | def __str__(self): |
| return "-".join(str(political_party) for political_party in self.political_parties) | | return "-".join(str(political_party) for political_party in self.political_parties) |
| | | |
| class Elections: | | class Elections: |
| _memory = {} | | _memory = {} |
| | | |
| def __init__(self, year): | | def __init__(self, year): |
| self.year = year | | self.year = year |
| self.votes = {} | | self.votes = {} |
| type(self)._memory[year] = self | | type(self)._memory[year] = self |
| | | |
| def register_party_or_coalition(self, participant): | | def register_party_or_coalition(self, participant): |
| self.votes[participant] = 0 | | self.votes[participant] = 0 |
| | | |
| def vote(self, participant): | | def vote(self, participant): |
| if participant in self.votes: | | if participant in self.votes: |
| self.votes[participant] += 1 | | self.votes[participant] += 1 |
| | | |
| def rig_elections(self, participant, amount, currency): | | def rig_elections(self, participant, amount, currency): |
| if participant in self.votes: | | if participant in self.votes: |
| if isinstance(participant, PoliticalParty): | | if isinstance(participant, PoliticalParty): |
| votes = participant.convert_currency_to_voters(amount, currency) | | votes = participant.convert_currency_to_voters(amount, currency) |
| if isinstance(participant, Coalition): | | if isinstance(participant, Coalition): |
| votes = max(political_party.convert_currency_to_voters(amount, currency) for political_party in participant.political_parties) | | votes = max(political_party.convert_currency_to_voters(amount, currency) for political_party in participant.political_parties) |
| self.votes[participant] += votes | | self.votes[participant] += votes |
| | | |
| def get_results(self): | | def get_results(self): |
| return {str(participant): votes for participant, votes in self.votes.items()} | | return {str(participant): votes for participant, votes in self.votes.items()} |
| | | |
| @classmethod | | @classmethod |
| def get_results_by_year(cls, year): | | def get_results_by_year(cls, year): |
| if year in cls._memory: | | if year in cls._memory: |
| return cls._memory[year].get_results() | | return cls._memory[year].get_results() |
| return {} | | return {} |
| t | | t | |
| yes_Bulgaria = PoliticalParty("Да, България", | | |
| "Ще щурмуваме всичко на север от Одрин!", | | |
| members=["Божо", "Ивайло Мирчев"]) | | |
| DSB = PoliticalParty("ДСБ", | | |
| "Помните ли Иван Костов?", | | |
| members=["Не-Иван-Костов", "Пак не е Иван Костов"]) | | |
| | | |
| DB = Coalition(yes_Bulgaria, DSB) | | |
| | | |
| PP = PoliticalParty("ПП", "Не сме сигурни все още...", members=["Асенката"]) | | |
| | | |
| yes_Bulgaria = PoliticalParty("Да, България", | | |
| "Ще щурмуваме всичко на север от Одрин!", | | |
| members=["Божо", "Ивайло Мирчев"]) | | |
| DSB = PoliticalParty("ДСБ", | | |
| "Помните ли Иван Костов?", | | |
| members=["Не-Иван-Костов", "Пак не е Иван Костов"]) | | |
| | | |
| DB = Coalition(yes_Bulgaria, DSB) | | |
| | | |
| GERB = PoliticalParty("ГЕРБ", | | |
| "Ту-тууу!", | | |
| members=["Бат'", "Бойко", "и", "сам", "стига"]) | | |
| SDS = PoliticalParty("СДС", | | |
| "Ние също сме шокирани, че все още съществуваме...", | | |
| members=["Румен, ама не Радев"]) | | |
22.03.2026 17:08