SergeySamoylov

One responsibility, two routes, one function

May 2nd, 2025
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. # Better than two holiday functions in https://www.youtube.com/watch?v=0U-RwnWaFIM
  2.  
  3. HOLIDAY_CONFIG = {
  4.     "single": {"days": 1, "msg": "Have fun on your holiday..."},
  5.     "payout": {"days": 5, "msg": "Paying out a holiday. Left: {remaining_days}"},
  6. }
  7.  
  8. def take_holiday(self, holiday_type: str) -> None:
  9.     config = HOLIDAY_CONFIG[holiday_type]  # Raises KeyError if invalid
  10.     if self.vacation_days < config["days"]:
  11.         raise ValueError(f"Not enough holidays for {holiday_type}.")
  12.     self.vacation_days -= config["days"]
  13.     print(config["msg"].format(remaining_days=self.vacation_days))
Advertisement
Add Comment
Please, Sign In to add comment