Lab 8, Warmup

Worksheet links

This part of the lab is available as a worksheet with solutions. You can view the shared document and print it, or make your own copy of it to work on it online.


Task 0: Warm up with dictionaries

You are given this dictionary:

backpack = {
      'money' : 10,
      'pencils' : 4,
      'umbrella' : True,
      'misc': ['lip balm', 'tissues', 'gum']

Task A: Fill in the blank below so that the following output results:

>>> ______________________________
['lip balm', 'tissues', 'gum']

Task B: Write a line of python code to add a calculator to the misc items in the backpack. How to see if the changes occurred? Come up with two different options:

Option 1:


Option 2:


Task C: Add a new key:value pair to the backpack dictionary that has key snack and value of one of your favorite snacks. Check the contents of your dictionary to make sure it is there (see options above).

Task D: What is printed when the following code executes:

for item in backpack:

Table of Contents