Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class WagerOutcome:
- """
- Base class for wager outcomes.
- """
- def __init__(self, name, price):
- self.name = name
- self.price = price
- def __str__(self) -> str:
- return self.name
- class TotalWagerWon(WagerOutcome):
- def __init__(self, price):
- super().__init__("Won", price)
- def payout(self, bet_amount: float) -> float:
- return bet_amount * (self.price - 1)
- def __str__(self) -> str:
- return f"{self.name}({self.price})"
- class TotalWagerLost(WagerOutcome):
- def __init__(self, price):
- super().__init__("Lost", price)
- def payout(self, bet_amount: float) -> float:
- return -bet_amount
- def __str__(self) -> str:
- return f"{self.name}({self.price})"
- class TotalWagerCancelled(WagerOutcome):
- def __init__(self, price):
- super().__init__("Cancelled", price)
- def payout(self, bet_amount: float) -> float:
- return 0
- def __str__(self) -> str:
- return f"{self.name}({self.price})"
- class TotalWagerHalfWon(WagerOutcome):
- def __init__(self, price):
- super().__init__("Half Won", price)
- def payout(self, bet_amount: float) -> float:
- return bet_amount * ((self.price - 1) / 2)
- def __str__(self) -> str:
- return f"{self.name}({self.price})"
- class TotalWagerHalfLost(WagerOutcome):
- def __init__(self, price):
- super().__init__("Half Lost", price)
- def payout(self, bet_amount: float) -> float:
- return bet_amount / 2
- def __str__(self) -> str:
- return f"{self.name}({self.price})"
- def usage():
- total_won = TotalWagerWon(1.95)
- print(total_won.__str__())
- print(total_won.payout(100))
- total_lost = TotalWagerLost(1.88)
- print(total_lost.__str__())
- print(total_lost.payout(100))
- total_cancelled = TotalWagerCancelled(1.76)
- print(total_cancelled.__str__())
- print(total_cancelled.payout(100))
- total_half_won = TotalWagerHalfWon(1.92)
- print(total_half_won.__str__())
- print(total_half_won.payout(100))
- total_half_lost = TotalWagerHalfLost(1.85)
- print(total_half_lost.__str__())
- print(total_half_lost.payout(100))
- if __name__ == '__main__':
- usage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement