''' Purpose: introduction to dictionary' ''' mappings = {} # a dictionary! otherwise known as dict in Python # {} is the empty dictionary print( "Before:", mappings ) mappings[ 1 ] = 'odd' # this is NOT indexing: the KEY is 1, and its VALUE is 'odd' mappings[ 2 ] = 'even' # the KEY is 2, and its VALUE is 'even' mappings[ 3 ] = 'odd' mappings[ 4 ] = 'even' mappings[ 5 ] = 'odd' mappings[ 6 ] = 'even' mappings[ 7 ] = 'odd' mappings[ 8 ] = 'even' mappings[ 9 ] = 'odd' mappings[ 'even' ] = 'a number is even if its remainder divided by 2 is 0' mappings[ 'odd' ] = 'a number is odd if its remainder divided by 2 is 1' print( "After:", mappings ) # dictionaries are UNORDERED; Python can order things in a dictionary however it likes # even if this output is printed in the same order, don't count on it when you are doing programs with dicts # dicts let us associate keys with values to solve problems # numbers = [] # numbers[ 0 ] = 12 # not a valid line! # print( numbers ) reply = input( 'Enter a number: ' ) n = int( reply ) status = mappings[ n ] print( n, status ) reply = input( 'Enter even or odd: ' ) meaning = mappings[ reply ] print( meaning )