1 |
h12 |
CS8 F18 |
Name: | ||||
---|---|---|---|---|
(as it would appear on official course roster) | ||||
Umail address: | @umail.ucsb.edu | |||
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-6.2 (Dictionaries, Sets)
ready? | assigned | due | points |
---|---|---|---|
true | Tue 11/27 08:00AM | Wed 12/05 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.
There is NO MAKEUP for missed assignments, and you may not submit work in advance, or on behalf of another person.
In place of that, we drop the four lowest scores (if you have zeros, those are the four lowest scores.)
READING ASSIGNMENT
Please read Perkovic 6.1-6.2 (Dictionaries, Sets). Then complete these problems and turn in your completed homework during your registered lab section..
(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.
-
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]
-
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.-
Pts Expresssion Value (5 pts) type(states)
(5 pts) type(states["OR"])
(5 pts) type(states["OR"]["capitol"])
(5 pts) type(states["CA"]["borders"])
-
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"]
-
Pts Expresssion Value (5 pts) "CA" in states["WA"]["borders"]
(5 pts) "NV" in states["OR"]["borders"]
(5 pts) ["AZ"] in states["CA"]["borders"]"AZ" in states["CA"]["borders"]
(5 pts) states["WA"]["borders"] < states["CA"]["borders"]
-