Advertisement
Guest User

Wager Outcome classes

a guest
May 24th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.25 KB | None | 0 0
  1. class WagerOutcome:
  2.     """
  3.    Base class for wager outcomes.
  4.    """
  5.     def __init__(self, name, price):
  6.         self.name = name
  7.         self.price = price
  8.  
  9.     def __str__(self) -> str:
  10.         return self.name
  11.  
  12.  
  13. class TotalWagerWon(WagerOutcome):
  14.     def __init__(self, price):
  15.         super().__init__("Won", price)
  16.  
  17.     def payout(self, bet_amount: float) -> float:
  18.         return bet_amount * (self.price - 1)
  19.  
  20.     def __str__(self) -> str:
  21.         return f"{self.name}({self.price})"
  22.  
  23.  
  24. class TotalWagerLost(WagerOutcome):
  25.     def __init__(self, price):
  26.         super().__init__("Lost", price)
  27.  
  28.     def payout(self, bet_amount: float) -> float:
  29.         return -bet_amount
  30.  
  31.     def __str__(self) -> str:
  32.         return f"{self.name}({self.price})"
  33.  
  34.  
  35. class TotalWagerCancelled(WagerOutcome):
  36.     def __init__(self, price):
  37.         super().__init__("Cancelled", price)
  38.  
  39.     def payout(self, bet_amount: float) -> float:
  40.         return 0
  41.  
  42.     def __str__(self) -> str:
  43.         return f"{self.name}({self.price})"
  44.  
  45.  
  46. class TotalWagerHalfWon(WagerOutcome):
  47.     def __init__(self, price):
  48.         super().__init__("Half Won", price)
  49.  
  50.     def payout(self, bet_amount: float) -> float:
  51.         return bet_amount * ((self.price - 1) / 2)
  52.  
  53.     def __str__(self) -> str:
  54.         return f"{self.name}({self.price})"
  55.  
  56.  
  57. class TotalWagerHalfLost(WagerOutcome):
  58.     def __init__(self, price):
  59.         super().__init__("Half Lost", price)
  60.  
  61.     def payout(self, bet_amount: float) -> float:
  62.         return bet_amount / 2
  63.  
  64.     def __str__(self) -> str:
  65.         return f"{self.name}({self.price})"
  66.  
  67.  
  68. def usage():
  69.     total_won = TotalWagerWon(1.95)
  70.     print(total_won.__str__())
  71.     print(total_won.payout(100))
  72.  
  73.     total_lost = TotalWagerLost(1.88)
  74.     print(total_lost.__str__())
  75.     print(total_lost.payout(100))
  76.  
  77.     total_cancelled = TotalWagerCancelled(1.76)
  78.     print(total_cancelled.__str__())
  79.     print(total_cancelled.payout(100))
  80.  
  81.     total_half_won = TotalWagerHalfWon(1.92)
  82.     print(total_half_won.__str__())
  83.     print(total_half_won.payout(100))
  84.  
  85.     total_half_lost = TotalWagerHalfLost(1.85)
  86.     print(total_half_lost.__str__())
  87.     print(total_half_lost.payout(100))
  88.  
  89.  
  90. if __name__ == '__main__':
  91.     usage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement