1
h12
CS8 M19-A
Name:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu section
Optional: name you wish to be called
if different from name above.
Optional: name of "homework buddy"
(leaving this blank signifies "I worked alone"

h12: Perkovic 6.1 (Dictionaries) and 6.2 (Sets)

ready? assigned due points
true Tue 07/23 09:30AM Tue 07/30 09:30AM

You may collaborate on this homework with AT MOST one person, an optional "homework buddy".

MAY ONLY BE TURNED IN IN THE LECTURE/LAB LISTED ABOVE AS THE DUE DATE,
OR IF APPLICABLE, SUBMITTED ON GRADESCOPE. There is NO MAKEUP for missed assignments;
in place of that, we drop the lowest scores (if you have zeros, those are the lowest scores.)


READING ASSIGNMENT

Please read Perkovic 6.1 (Dictionaries) and 6.2 (Sets). Then complete these problems and turn in your completed homework in lecture on the due date.

  1. (10 pts) Please fill in the information at the top of this homework sheet, including your name and umail address. Put the time your discussion section starts () in the space indicated (the one you are registered for—even if you usually attend a different one.) If the other two items apply, please fill them in as well. Please do this every single time you submit homework for this class.
  2. Suppose we define the following Python variable:

    capitals = { "CA":"Sacramento", "NV":"Carson City",
    	     "AZ":"Phoenix", "WA":"Olympia", "OR":"Salem" }
    

    What would the value of each of the following Python expressions be? Fill in the blanks. Remember that type returns types in the format <class 'int'>, <class 'list'>, <class 'str'>, etc. Use the correct value for full credit.

    |Pts|Expresssion|Value| |---|-----------|-----| | (5 pts) | `type(capitals)`| | | (5 pts) | `capitals["CA"]` | | | (5 pts) | `type(capitals["NV"])` | | | (5 pts) | `len(capitals["WA"])`| | | (5 pts) | `capitals["OR"][2:6]`| |
  3. Suppose we define states as follows (note that these definitions are not necessarily correct or complete):

    states = {
     "AZ" : { "capital" : "Phoenix", "borders" : {"AZ","NV"} },
     "CA" : { "capital" : "Sacramento", "borders" : {"AZ","NV","OR"} },
     "NV" : { "capital" : "Carson City", "borders" : {"OR","AZ","CA"} },
     "OR" : { "capital" : "Salem", "borders" : {"WA","CA","NV"} },
     "WA" : { "capital" : "Olympia", "borders" : {"OR"} }
    }
    
    
    

    What would the value of each of the following Python expressions be? Fill in the blanks. Remember that type returns types in the format <class 'int'>, <class 'list'>, <class 'str'>, etc. Use the correct value for full credit.

    1. Pts Expresssion Value
      (5 pts) type(states)  
      (5 pts) type(states["OR"])  
      (5 pts) type(states["OR"]["capital"])  
      (5 pts) type(states["CA"]["borders"])  
    2. Pts Expresssion Value
      (5 pts) len(states.keys())  
      (5 pts) len(states["OR"].keys())  
      (5 pts) len(states["NV"]["capital"])  
      (5 pts) states["OR"]["capital"]  
      (5 pts) states["AZ"]["borders"]  
    3. Pts Expresssion Value
      (5 pts) "CA" in states["CA"]["borders"]  
      (5 pts) "NV" in states["CA"]["borders"]  
      (5 pts) "AZ" in states["CA"]["borders"]  
      (5 pts) states["WA"]["borders"] < states["CA"]["borders"]