Lab 10: Knowledge Check

These questions check your knowledge of concepts from this lab. Use the button at the bottom to show your answers once you've attempted them.

  1. True or false: The keys of a dictionary can be accessed by putting their associated value in square brackets after the dictionary.
    True False
  2. If we run the following code, what is final the value of the variable taxes?
    taxes = { 'income': 50000 }
    taxes['taxable'] = taxes['income']
    taxes['income'] += 10000
    taxes['tax'] = taxes['taxable'] * 0.1

    1. { 'income': 50000, 'taxable': 50000, 'tax': 5000 }
    2. { 'income': 60000, 'taxable': 50000, 'tax': 5000 }
    3. { 'income': 60000, 'taxable': 60000, 'tax': 5000 }
    4. { 'income': 60000, 'taxable': 60000, 'tax': 6000 }
  3. Which of the following statements are true about dictionaries? (pick one or more)
    1. You can use .append to add key/value pairs.
    2. You can use .insert to add key/value pairs.
    3. You can use square brackets to access the value associated with a particular key.
    4. You can use .get to access the value associated with a particular key.
    5. You can use .pop to remove a key/value pair if you only know the value.
    6. The in operator checks keys and values.
    7. You can use dict[key] = value to assign a value to a dictionary slot specified using a key, even if that key isn't in the dictionary yet.

Table of Contents