''' Purpose: introduction to dictionary' ''' mappings = {} # dictionaries are defined using {} (curly braces) mappings[ 0 ] = 'even' mappings[ 1 ] = 'odd' mappings[ 2 ] = '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' # Adding a mapping to a dictionary: # dictionary_name[key] = value # ex. mappings[0] = 'even' # So our dictionary looks like { 0: 'even', 1: 'odd', ...} where ... are the other mappings reply = input( 'Enter a number: ' ) n = int( reply ) # Getting values in our dictionary at keys (in this example, the key is n) # status = mappings[ n ] # Getting the value for a key (dictionaryname[key] will give you the value at the key) # Will give you the value if the key exists in our dictionary (mappings[3] will give you 'odd') # Will give you an error if the key doesn't exist in our dictionary (ex.mappings[14] will give you an error) status = mappings.get( n ) # Getting the value for a key (dictionaryname.get( key ) will give you the value at that key) # Will give you the value if the key exists (mappings.get(3) will give you 'odd') # Will give you None if the key doesn't exist in our dictionary (mappings.get(14) will give you None) print( n, status ) reply = input( 'Enter even or odd: ' ) meaning = mappings[ reply ] print( meaning )