class Time(object): def __init__(self, hour, minute, ampm): self.hour = hour self.minute = minute self.ampm = ampm # midnight will be AM!!; ampm = 'AM' or 'PM' # This function returns the time 1 minute after time denoted by self def next(self): next = Time(0,0,'') if self.hour == 11 and self.minute == 59: if self.ampm == 'AM': h,m,a = 12,0,'PM' else: h,m,a = 12,0,'AM' elif self.hour == 12 and self.minute == 59: h,m,a = 1,0,self.ampm elif self.minute == 59: h,m,a = self.hour+1,0,self.ampm else: h,m,a = self.hour,self.minute+1,self.ampm return Time(h,m,a) # This function returns the time 1 minute before time denoted by self def previous(self): pass # This function returns the time nminutes seconds after time denoted by self def add(self,nminutes): t = Time(self.hour,self.minute,self.ampm) for i in range(nminutes): t = t.next() return t # This function returns the time nminutes before time denoted by self def sub(self,nminutes): pass # This function returns number of minutes that have elapsed since midnight until time denoted by self def minutes_since_midnight(self): pass # This function returns True if time denoted by self is AFTER time denoted by t def after(self,t): pass # This function returns True if time denoted by self is EQUAL TO time denoted by t def equals(self,t): return ((self.minute == t.minute) and (self.hour == t.hour) and (self.ampm == t.ampm)) # This function returns True if time denoted by self is BEFORE time denoted by t def before(self,t): pass # This function returns the number of seconds between time denoted by self and time denoted by t def minutes_between(self,t): pass # This function returns a string representation of the time denoted by self def __str__(self): def two_spaces(n): if n<10: return '0'+str(n) else: return str(n) return two_spaces(self.hour)+":"+two_spaces(self.minute)+self.ampm