1. Code Tracing [20 points]
What does the following code print?
Be certain to show your work,
and also very clearly circle your answer!
def ct_versionB(L):
s = set()
d = dict()
for v in L:
s.add(v)
if (v in d):
d[v] += v
else:
d[v] = v
print(f's = {s}')
print(f'd = {d}')
ct_versionB(['z','o','o','m','z','z'])
2. Reasoning Over Code [20 points]
What input makes the following function return True?
Be certain to show your work,
and also very clearly circle your answer!
def rc_versionB(d):
t = ''
s = [t] * len(d)
for count in range(4):
t = d[t]
s[count] = t
return s == ['d','o','g', ''] # last value is the empty string
3. Free Response [60 points]
Say we are given the following multiline string of courseData:
courseData = '''
name>role>course
koz>prof>112
lisanne>ta>112
mike>prof>112
kelly>prof>110
jimothy>ta>110
'''
Write the function makeCourseDictionary(courseData) that takes data formatted
like this, and returns a dictionary mapping each course to another dictionary
that maps each role in that course to a set of the names of people in that
role for that course.
For example, for the courseData given above, makeCourseDictionary(courseData)
returns this:
{
'112':
{'prof': {'mike', 'koz'},
'ta': {'lisanne'}
},
'110':
{'prof': {'kelly'},
'ta': {'jimothy'}
}
}
Hint: note that the table begins with a blank line and then the
line of column labels. Also, the table ends with a blank line.