1
h11
CS8 W19
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"

h11: Perkovic 6.1-6.2 (Dictionaries)

ready? assigned due points
true Thu 03/07 02:00PM Wed 03/13 09:00AM

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-6.2 (Dictionaries). Then complete these problems and turn in your completed homework during your registered lab section..

  1. (10 pts) Please fill in the information at the top of this homework sheet, including your name and umail address. If the other two items apply, please fill them in as well. Please do this every single time you submit homework for this class. It is important to fill in both name and umail every time, since handwriting is sometimes difficult to decipher. Having both helps us ensure you get credit for your work.

    DO NOT staple, paper clip, spit-fold-and-tear, or do ANYTHING that would make it difficult to automatically feed your paper through a scanner.

  2. Suppose we define the following Python variable:

    capitols = { "CA":"Sacramento", "NV":"Carson City",
    	     "AZ":"Phoenix", "WA":"Seattle", "OR":"Portland" }
    

    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(capitols)  
    (5 pts) capitols["CA"]  
    (5 pts) type(capitols["CA"])  
    (5 pts) len(capitols["OR"])  
    (5 pts) capitols["OR"][4:8]  
  3. Suppose we define states as follows:

    states = {
     "AZ" : { "capitol" : "Phoenix", "borders" : {"AZ","NV"} },
     "CA" : { "capitol" : "Sacramento", "borders" : {"AZ","NV","OR"} },
     "NV" : { "capitol" : "Carson City", "borders" : {"OR","AZ","CA"} },
     "OR" : { "capitol" : "Portland", "borders" : {"WA","CA","NV"} },
     "WA" : { "capitol" : "Seattle", "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"]["capitol"])  
      (5 pts) type(states["CA"]["borders"])  
    2. Pts Expresssion Value
      (5 pts) len(states.keys())  
      (5 pts) len(states["NV"].keys())  
      (5 pts) len(states["OR"]["capitol"])  
      (5 pts) states["OR"]["capitol"]  
      (5 pts) states["WA"]["borders"]  
    3. Pts Expresssion Value
      (5 pts) "CA" in states["WA"]["borders"]  
      (5 pts) "NV" in states["OR"]["borders"]  
      (5 pts) "AZ" in states["CA"]["borders"]  
      (5 pts) states["WA"]["borders"] < states["CA"]["borders"]