class Date: """ a blueprint (class) for objects that represent calendar days """ def __init__( self, mo, dy, yr ): """ the Date constructor """ self.month = mo self.day = dy self.year = yr def __str__( self ): """ used for printing Dates """ s = "{:02d}/{:02d}/{:04d}".format(self.month,self.day,self.year) return s def is_leap_year( self ): """ anyone know the rule? Every year that is divisible by 4 is a leap year However, a year that is divisible by 100 is NOT a leap year However, a year that is divisible by 400 IS a learp year """ if self.year % 400 == 0: return True if self.year % 100 == 0: return False return self.year % 4 == 0 def is_before(self, d2): """ if self is before d2, returns True; otherwise returns False""" '''This version is probamatic''' if self.year < d2.year: return True else: return False if self.month < d2.month: return True else: return False if self.day < d2.day: return True else: return False return False def is_before(self, d2): """ if self is before d2, returns True; otherwise returns False""" '''This version works correctly''' if self.year < d2.year: return True if self.month < d2.month and self.year == d2.year: return True if self.day < d2.day and self.month == d2.month: return True return False def set_year( self, yr ): """ Set the year value """ self.year = yr def set_month( self, mo ): """ Set the month value """ self.month = mo def set_day( self, dy ): """ Set the day value """ self.day = dy d = Date( 11, 8, 2011 ) print( d ) # 11/08/2011 print( d.is_leap_year() ) # False d2 = Date( 1, 1, 2012 ) print( d2 ) # 01/01/2012 print( d2.is_leap_year() ) # True