Week 10- Final Review

1) This program crashes when run. Which line causes an error? Why?

def aFunction(a, b):
    a = b
    c = a + 1
    return c

a = 4
b = 8
b = aFunction(a,b)
print a,b,c

2) What is printed?

def aFunction(b,c):
    b = [4,5,6]
    c[0] = 50

a = [1,2,3]
b = a
c = b[:]
aFunction(c,a)
b[1] = 20
print "a=", a
print "b=", b
print "c=", c

3) What is printed?

a = set([1, 2, 3])
print a #a
a.add(2)
a.add(5)
a.remove(1)
print a #b
print a.intersection(set([1,2,4,5])) #c
b = {0:"q",1:"w",2:"y"}
print b #d
print b[2] #e
print b.keys() #f
print b.values() #g
c = []
for k,v in b.items():
    if k in a:
        c.append(k)
print c #h

4) Write pseudocode for a function that takes a list and a dictionary. The function should return a set that corresponds to all the dictionary keys that have values in the list.