15-112 Spring 2013 Quiz 7
* 15 Minutes. No calculators, no notes, no books, no computers.
* Show your work. Circle your answers.
1.
Free Response: numberOfUniqueValues [25 pts]
Write the function numberOfUniqueValues(d) that takes a dictionary d (that,
as you recall, maps keys to values), and returns a count of the number of unique
values (not keys!) in that dictionary. For full credit, you should do this as
efficiently as possible, which may involve using a set.
2. Free
Response: Clicky [75 pts]
On the back of this page (and not here!), write all the code (from scratch,
including the run function) required to play the super-fun game of “Clicky”.
The game starts with a circle placed in the middle of the window. Each time you
press the mouse in the circle, it disappears. Each time you press the mouse
anywhere except inside the circle (which is guaranteed to happen if you click
when the circle is not visible), the circle appears centered on the location
where you clicked.
3.
Bonus/Optional: [5 pts] Indicate what the following will
print:
def h(d, s=set()):
for k in d:
try:
if (d[d[k]] not in s): s.add(k)
except:
s.add(k+2)
return s
print sorted(list(h({1:2,2:3,3:1,4:3,5:6})))