# ShowSimpleDate.py """ Module contains a script that illustrates the use of the class SimpleDate.""" def isLeapYear(y): """ Returns True if y is a leap year. False otherwise PreC: y is a positive integer """ return ((y%100>0) and y%4==0) or ((y%100==0) and (y%400==0)) class SimpleDate: """ Represents a date. Attributes m : int, index of month d : int, day y : int, year s : str, date string """ # Class variables... TheMonths =['','January','February','March','April','May','June', 'July','August','September','October','November','December'] nDays =[0,31,28,31,30,31,30,31,31,30,31,30,31] def __init__(self,s): """ Returns a SimpleDate representation of the date encoded in s. Pre: s is a date string of the form 'm/d/y' where m is a string that encodes the month index, d is a string that encodes the day, and y is a string that encodes the year. """ v = s.split('/') self.m = int(v[0]) self.d = int(v[1]) self.y = int(v[2]) self.s = s def __str__(self): """ Pretty prints the date encoded in self """ return self.TheMonths[self.m]+' '+str(self.d)+', '+str(self.y) def Tomorrow(self): """ Returns a SimpleDate that encodes the date of the day after the date encoded by self.""" m = self.m d = self.d y = self.y Last = self.nDays[m] if isLeapYear(y) and m==2: Last+=1 if d