# A Date object represents a month and day such as 12/25. # This version adds special methods for printing and comparison. class Date: # Constructor initializes the state of new # Date objects as they are created by client code. def __init__(self, month, day): # set the attributes (the state in each Date object) self.month = month self.day = day # Compares dates for equality. def __eq__(self, other): return self.month == other.month \ and self.day == other.day # Returns a string representation of a Date, such as "9/19". def __str__(self): return str(self.month) + "/" + str(self.day) # Advances the Date's state to the next day, # wrapping into the next month/year as necessary. def advance(self): self.day += 1 if self.day >= self.days_in_month(): # wrap to next month self.month += 1 self.day = 1 if self.month > 12: # wrap to next year self.month = 1 # Returns the number of days in this Date's month. def days_in_month(self): if self.month in {4, 6, 9, 11}: return 30 elif self.month == 2: return 28 else: return 31