# Events.py Copyright (c) Kari Laitinen # http://www.naturalprogramming.com # 2006-05-18 File created. # 2009-01-22 class ISODate used in place of Date # 2022-12-18 Converted to Python 3. # During compilation and execution, the file ISODate.py must be in # the same folder together with this program. from ISODate import ISODate class Event ( ISODate ) : def __init__( self, year_of_event, month_of_event, day_of_event, given_event_description ) : ISODate.__init__( self, year_of_event, month_of_event, day_of_event ) self.event_description = given_event_description def __str__( self ) : date_of_event = ISODate( self.this_year, self.this_month, self.this_day ) return "%s %s" % ( date_of_event, self.event_description ) def __lt__( self, event_to_compare_to ) : return self.is_earlier_than( event_to_compare_to ) def __eq__( self, event_to_compare_to ) : return self.is_equal_to( event_to_compare_to ) def __gt__( self, event_to_compare_to ) : return self.is_later_than( event_to_compare_to ) # The main program begins. birth_of_lennon = Event( 1940, 10, 9, "John Lennon was born." ) birth_of_einstein = Event( 1879, 3, 14, "Albert Einstein was born." ) list_of_events = [] list_of_events.append( birth_of_lennon ) list_of_events.append( birth_of_einstein ) list_of_events.append( Event( 1980, 12, 8, "John Lennon was shot in New York." ) ) print( "\nEvents of list_of_events:" ) event_index = 0 while event_index < len( list_of_events ) : print( "\n %s" % list_of_events[ event_index ], end="" ) event_index += 1 another_event_list = [] another_event_list.insert( 0, Event( 1926, 6, 1, "Marilyn Monroe was born." ) ) another_event_list.insert( 0, Event( 1962, 8, 5, "Marilyn Monroe died." ) ) another_event_list.append( Event( 1769, 8, 15, "Napoleon Bonaparte was born." ) ) another_event_list.append( Event( 1881,10, 25, "Pablo Picasso was born." ) ) print( "\n\nEvents of another_event_list:" ) for event_index in range( len( another_event_list ) ) : print( "\n %s" % another_event_list[ event_index ], end="" ) list_of_events.sort() another_event_list.sort() list_of_events = another_event_list + list_of_events print( "\n\nEvents of list_of_events:" ) for event_on_list in list_of_events : print( "\n %s" % event_on_list, end="" ) print( "\n" )