IT 117: Intermediate to Scripting
Answers to Class 6 Ungraded Quiz

  1. 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'
  2. What is the length of an empty dictionary?
    0
  3. Write the Python statement to create an entry in the students dictionary for a student with student ID '0123456' whose name is 'John Smith'.
    students['0123456'] = 'John Smith'
  4. 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
  5. 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
  6. Write the Python statement you would use to delete the entry in the students dictionary with key value '0123456'.
    del students['0123456']
  7. 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
  8. What does the length of a dictionary mean?
    the number of key - value pairs in the dictionary
  9. Write the Python expression you would use to get the number of entries in a dictionary named students.
    len(students)
  10. Can dictionary entries be accessed by their position?
    no. entries in a dictionary have no definite position