IT 117: Intermediate Scripting
Answers to Class 6 Ungraded Quiz


  1. Write the Python statement to create an empty dictionary named students.
    students = {}
  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 length of the dictionary students.
    len(students)
  10. Can dictionary entries be accessed by their position?
    no. entries in a dictionary have no definite position