IT 117: Intermediate Scripting
Quiz 2 Answers

  1. What are the entries in a dictionary?
    key - value pairs
  2. Are dictionaries sequences?
    no
  3. If I had a dictionary of email addresses named emails, what would I write to get the email for the person named 'Chris'?
    emails['Chris']
  4. Write the Python statement to create an empty dictionary named empty.
    empty = {}
  5. If I wanted to add the email address 'dave.souza@gmail.com' to the dictionary emails using the key 'Dave', what Python statement would I write?
    emails['Dave'] = 'dave.souza@gmail.com'
  6. Write the Python statement to change the value for 'Dave' in the dictionary above to 'dave.souza@hotmail.com'
    emails['Dave'] = 'dave.souza@hotmail.com'
  7. Write the Python expression you would use to test whether the students dictionary contains an entry for a student with the ID '0123456'.
    '0123456' in students
  8. Write the Python expression you would use to test whether the students dictionary DOES NOT contain an entry for a student with the ID '0123456'.
    '0123456' not in students
  9. Write the Python statement you would use to delete the entry in the students dictionary with key value '0123456'.
    del students['0123456']
  10. What would happen if you tried to delete a dictionary entry using a key that was NOT in the dictionary?
    you would get a KeyError exception