Quiz8

Quiz8 Version C



Important notes:
  1. Do not start until you are instructed to do so!
  2. We suggest you do not use your browser's zoom feature. Instead...
  3. You will have 15 minutes once the proctor says to start.
  4. You will have brief additional time after we stop to scan and submit your solutions.

  5. Just before the quiz...
    1. Have a fully-charged smartphone and laptop, and still plug both in if possible
    2. Log into Gradescope on your phone
    3. Change the screen timeout setting on your phone to never, so your screen doesn't go black if you don't interact with your screen for a while.
      • iPhones: Settings / Display & Brightness / Auto-Lock / Never
      • Android: Settings / Display / Screen timeout / 10 minutes (or the maximum amount of time)
    4. Turn on Do Not Disturb (or otherwise turn off all notifications).
    5. Position your webcam so we can see:
      • Your desk
      • The paper you are working on
      • Your writing utensil(s)
      • Both of your hands
      • Your phone
      • Optionally: one double-sided "help sheet" (with anything on it that you wish)

  6. During the quiz:
    1. You may not ask questions during the exam.
      • If you are unsure how to interpret a problem, take your best guess.
    2. You may not touch your laptop or webcam.
      • This includes muting yourself at any point; the proctors may mute you though.
    3. All of these must be visible at all times:
      • Your desk
      • The paper you are working on
      • Your writing utensil(s)
      • Both of your hands
      • Your phone, with the quiz webpage
      • Optionally: one double-sided "help sheet" (with anything on it that you wish)
    4. For any tech fails (laptop or internet stops working, etc.):
      1. Stop taking the quiz
      2. Fill out this Google Form immediately
      3. We will email you soon to set up a 1-on-1 oral quiz with the course faculty

  7. After the quiz:
    1. Follow all proctor instructions on how to end the quiz.
    2. Keep everything in view (as noted above) until the proctor calls "time".
    3. When instructed, use your phone to scan your quiz and submit the PDF to Gradescope.
    4. After submitting to Gradescope, hold your phone up to the webcam to show the receipt.
    5. Even then, remain in quiz mode until the proctor calls "all clear"


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_versionC(L):
    s = set()
    d = dict()
    for v in L:
        s.add(v)
        if (v in d):
            d[v] += min(s)
        else:
            d[v] = v
    print(f's = {s}')
    print(f'd = {d}')

ct_versionC([8,8,4,8,4,2])


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_versionC(d):
    s = t = 0
    for count in range(4):
        t = d[t]
        s += t
    return s == 123



3. Free Response [60 points]

Say we are given the following multiline string of foodData:
foodData = '''
name,category,flavor
apple,fruit,sweet
broccoli,vegetable,neutral
turnip,vegetable,bitter
melon,fruit,sweet
plantain,fruit,neutral
'''
Write the function makeFoodDictionary(foodData) that takes data formatted like this, and returns a dictionary mapping each category (i.e. fruit, vegetable, etc) to another dictionary that maps each observed flavor (i.e. we have seen bitter or neutral) to a set of the names of foods.

For example, for the foodData given above, makeFoodDictionary(foodData) returns this:
{
    'fruit': 
            {'sweet': {'melon', 'apple'}, 
             'neutral': {'plantain'}
            }, 
    'vegetable': 
            {'neutral': {'broccoli'}, 
             'bitter': {'turnip'}
            }
}
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.