- class BaseWallet:
- def __init__(self, name, amount):
- self.name = name
- self.amount = amount
- def spend_all(self):
- if self.amount > 0:
- self.amount = 0
- def to_base(self):
- return self.amount * self.exchange_rate
- def __eq__(self, other):
- if isinstance(other, (RubbleWallet, DollarWallet, EuroWallet)):
- if self.amount == other.amount and type(self) == type(other):
- return True
- else:
- return False
- def __add__(self, other):
- if isinstance(other, (int, RubbleWallet, DollarWallet, EuroWallet)):
- sc = other if type(other) == int else other.amount * (other.exchange_rate/self.exchange_rate)
- return self.__class__(self.name, self.amount + sc)
- def __iadd__(self, other):
- if isinstance(other, (int, RubbleWallet, DollarWallet, EuroWallet)):
- sc = other if type(other) == int else other.amount * (other.exchange_rate / self.exchange_rate)
- self.amount += sc
- return self
- def __radd__(self, other):
- return self + other
- def __sub__(self, other):
- if isinstance(other, (int, RubbleWallet, DollarWallet, EuroWallet)):
- sc = other if type(other) == int else other.amount * (other.exchange_rate / self.exchange_rate)
- return self.__class__(self.name, self.amount - sc)
- def __rsub__(self, other):
- if isinstance(other, (int, RubbleWallet, DollarWallet, EuroWallet)):
- sc = other if type(other) == int else other.amount * (other.exchange_rate/self.exchange_rate)
- return self.__class__(self.name, sc - self.amount)
- def __isub__(self, other):
- if isinstance(other, (int, RubbleWallet, DollarWallet, EuroWallet)):
- sc = other if type(other) == int else other.amount * (other.exchange_rate / self.exchange_rate)
- self.amount -= sc
- return self
- def __mul__(self, other):
- if isinstance(other, (int, RubbleWallet, DollarWallet, EuroWallet)):
- sc = other if type(other) == int else other.amount * (other.exchange_rate/self.exchange_rate)
- return self.__class__(self.name, self.amount * sc)
- def __imul__(self, other):
- if isinstance(other, (int, RubbleWallet, DollarWallet, EuroWallet)):
- sc = other if type(other) == int else other.amount * (other.exchange_rate / self.exchange_rate)
- self.amount *= sc
- return self
- def __rmul__(self, other):
- if isinstance(other, (int, RubbleWallet, DollarWallet, EuroWallet)):
- sc = other if type(other) == int else other.amount * (other.exchange_rate/self.exchange_rate)
- return self.__class__(self.name, sc * self.amount)
- def __truediv__(self, other):
- if isinstance(other, (int, RubbleWallet, DollarWallet, EuroWallet)):
- sc = other if type(other) == int else other.amount * (other.exchange_rate/self.exchange_rate)
- return self.__class__(self.name, self.amount / sc)
- def __itruediv__(self, other):
- if isinstance(other, (int, RubbleWallet, DollarWallet, EuroWallet)):
- sc = other if type(other) == int else other.amount * (other.exchange_rate / self.exchange_rate)
- self.amount /= sc
- return self
- class RubbleWallet(BaseWallet):
- def __init__(self, name, amount):
- super().__init__(name, amount)
- self.exchange_rate = 1
- def __repr__(self):
- return f"Rubble Wallet {self.name} {self.amount}"
- class DollarWallet(BaseWallet):
- def __init__(self, name, amount):
- super().__init__(name, amount)
- self.exchange_rate = 60
- def __repr__(self):
- return f"Dollar Wallet {self.name} {self.amount}"
- class EuroWallet(BaseWallet):
- def __init__(self, name, amount):
- super().__init__(name, amount)
- self.exchange_rate = 70
- def __repr__(self):
- return f"Euro Wallet {self.name} {self.amount}"
[text] 17
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new:
File Description
- 17
- Paste Code
- 26 Nov-2022
- 3.98 Kb
You can Share it:
Latest Code Pastes