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[:]
b[1] = 20
print "a=", a
print "b=", b
print "c=", c

3) What is printed?

a = set([1, 2, 3])
print a #a
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:
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.