Skip to content

Instantly share code, notes, and snippets.

@akirap3
Last active December 31, 2020 06:15
Show Gist options
  • Save akirap3/d1ce4264b0ad38f8537a088a1f9c0ec0 to your computer and use it in GitHub Desktop.
Save akirap3/d1ce4264b0ad38f8537a088a1f9c0ec0 to your computer and use it in GitHub Desktop.
class WeekDayError(Exception):
    pass

class Weeker:
    __weekdays = ['Mon','Tus','Wed', 'Thu','Fri','Sat', 'Sun']
    
    def __init__(self,day):
        try:
            self.__stat = self.__weekdays.index(day)
        except:
            raise WeekDayError
    
    def __str__(self):
        return self.__weekdays[self.__stat]
        
    def add_days(self, n):
        self.__stat = (self.__stat + n ) % 7
        
    def subtract_days(self, n):
        self.__stat = (self.__stat - n ) % 7
        
try:
    weekday = Weeker('Mon')
    print(weekday)
    weekday.add_days(15)
    print(weekday)
    weekday.subtract_days(23)
    print(weekday)
    weekday = Weeker('Monday')
except WeekDayError:
    print("Sorry, I can't serve your request.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment