Week 10 — Quiz (auto-graded) · Tuples, Dictionaries & Sets
Course: Introduction to Computer Science — CS1 / Programming Fundamentals in Python (CSCI 1101) · Silver Oak University (fictional sample) · Prof. Okafor
Objective tested: Objective 6 — tuples & immutability; dictionaries (lookup, update, .get(), KeyError); sets (dedup, membership); choosing a collection.
Points: 10 (1 each) · Assignment group: Quizzes (10% of grade) · Due: end of Module 10.
This is the human-readable quiz with its vetted answer key and feedback. The import-ready Classic QTI is in
F-quiz-week-10-qti.xml(generated by the shared validated script — parses with 10 items, every single-answer item exactly one correct). Execution gate: PASS — every "what does this print?" key below was produced by actually running the code in Python, not hand-traced. The Canvas placement block is at the bottom of this file.
Blueprint
| # | Type | Concept | Objective |
|---|---|---|---|
| 1 | Multiple choice | Predict the output — dictionary lookup d[key] |
6 |
| 2 | Multiple choice | Predict the output — dictionary update (d[k] = d[k] + n) |
6 |
| 3 | Multiple choice | Predict the output — set dedup (len of a set) |
6 |
| 4 | Multiple choice | Set membership / unordered (in) |
6 |
| 5 | Multiple choice | Tuple immutability — assigning to an element raises TypeError |
6 |
| 6 | Multiple choice | Which collection? — look up by name → dictionary | 6 |
| 7 | Multiple choice | Debugging — KeyError on a missing key (and the fix) |
6 |
| 8 | True / False | "d['missing'] returns None" misconception |
6 |
| 9 | Multiple answer | True statements about dicts, sets, and tuples | 6 |
| 10 | Matching | Collection → property (list / tuple / dict / set) | 6 |
No trick questions; distractors are plausible mis-traces (treating d[missing] as None, assuming a set keeps order, counting duplicates, picking the wrong collection, wrong error type).
Questions, key, and feedback
Q1 (MC). What does this program print?
caps = {"France": "Paris", "Japan": "Tokyo"}
print(caps["Japan"])
- A.
Paris - B.
Tokyo✅ - C.
Japan - D. an error
Feedback: A dictionary looks up a value by its key.caps["Japan"]returns the value stored under the key"Japan", which isTokyo. (Run-verified:Tokyo."Japan"is the key, not the value, so A and C are wrong; the key exists, so it doesn't error.)
Q2 (MC). What does this program print?
inventory = {"pen": 3}
inventory["pen"] = inventory["pen"] + 2
print(inventory["pen"])
- A.
3 - B.
5✅ - C.
2 - D.
32
Feedback:inventory["pen"]is3;3 + 2 = 5, and assigning back to the same key updates it. So the value becomes5. (Run-verified:5. There's only one value per key — the old3is replaced. D,32, would be string-joining, but these are numbers.)
Q3 (MC). What does this program print?
print(len({3, 3, 4, 5, 5}))
- A.
5 - B.
3✅ - C.
4 - D.
2
Feedback: A set keeps only unique values, so{3, 3, 4, 5, 5}becomes{3, 4, 5}— three distinct items.lenof that is3. (Run-verified:3. A,5, counts the duplicates as if it were a list.)
Q4 (MC). Given s = {10, 20, 30}, what does this print?
print(20 in s)
print(25 in s)
- A.
TruethenTrue - B.
TruethenFalse✅ - C.
FalsethenFalse - D.
20then25
Feedback:inasks whether a value is in the set.20is ins→True;25is not →False. (Run-verified:TruethenFalse. Membership gives a Boolean, not the value, so D is wrong. A set is unordered, butinstill works perfectly.)
Q5 (MC). This program crashes:
point = (3, 4)
point[0] = 9
What is wrong?
- A. Nothing; point becomes (9, 4)
- B. A tuple is immutable, so assigning to point[0] raises a TypeError ✅
- C. Tuples can't be indexed, so point[0] is illegal
- D. You must write point(0) instead of point[0]
Feedback: A tuple is immutable — you cannot change an element after it's created — so point[0] = 9 raises TypeError: 'tuple' object does not support item assignment. (Run-verified. You CAN read point[0] (that's 3), so C is wrong; tuples use square brackets for indexing, so D is wrong. To "change" it, build a new tuple.)
Q6 (MC). You want to store each employee's salary so you can look it up by the employee's name. Which collection is the best fit?
- A. a list
- B. a tuple
- C. a dictionary ✅
- D. a set
Feedback: "Look it up by name" means you want key → value lookup — that's a dictionary (name = key, salary = value). (A list/tuple find things by numeric position, not by name; a set holds unique values with no associated data.)
Q7 (MC). This program is supposed to print Ada's score, but it crashes:
scores = {"Sam": 88, "Mo": 72}
print(scores["Ada"])
What is the error, and the best fix?
- A. A SyntaxError; add a colon
- B. A KeyError because "Ada" isn't a key; use scores.get("Ada") or check if "Ada" in scores ✅
- C. No error; it prints None
- D. An IndexError; use scores[0] instead
Feedback: "Ada" is not a key, so scores["Ada"] raises KeyError: 'Ada'. To avoid the crash, use scores.get("Ada") (returns None) or guard with if "Ada" in scores. (Run-verified: it's a KeyError, not None (C) and not an IndexError (D) — dictionaries are keyed by name, not by number.)
Q8 (True / False). "In Python, looking up a missing key with square brackets, like d['missing'], returns None."
- True
- False ✅
Feedback: False. d["missing"] raises a KeyError (a crash). Only d.get("missing") returns None. This is the single most common dictionary mistake — square brackets crash on a missing key. (Run-verified.)
Q9 (Multiple answer — select all that apply). Which of the following statements are true?
- A. A set automatically removes duplicate values ✅
- B. d.get(key) returns None instead of crashing if the key is missing ✅
- C. A tuple's elements can be changed with t[0] = ...
- D. In a dictionary, key in d checks whether key is one of the keys ✅
- E. A set keeps its elements in the exact order you typed them
Feedback: Sets dedupe (A); .get() is the safe lookup (B); in on a dict checks keys (D). C is false — tuples are immutable (t[0] = ... raises a TypeError). E is false — sets are unordered; never rely on a set's print order.
Q10 (Matching). Match each collection to the property that best describes it.
| Collection | Correct property |
|---|---|
| list | Ordered and changeable (mutable) |
| tuple | Ordered and unchangeable (immutable) |
| dict | Stores key → value pairs (look up by key) |
| set | Unordered collection of unique values |
Feedback: A list is ordered and mutable; a tuple is ordered and immutable; a dict maps keys to values; a set holds unique values with no order. These four properties are exactly how you choose the right collection for a job.
Answer key (quick reference)
| Q | Answer |
|---|---|
| 1 | B (Tokyo) |
| 2 | B (5) |
| 3 | B (3) |
| 4 | B (True, False) |
| 5 | B (TypeError) |
| 6 | C (dictionary) |
| 7 | B (KeyError + .get()/in) |
| 8 | False |
| 9 | A, B, D |
| 10 | list→ordered+mutable / tuple→ordered+immutable / dict→key→value / set→unique+unordered |
Quality gate (self-checked): each single-answer item has exactly one correct option; the multiple-answer item keys A, B, D (and requires C and E unselected); the matching item pairs four collections to four distinct properties. Execution gate: PASS — the keys for the predict-the-output items (Q1 Tokyo; Q2 5; Q3 3; Q4 True/False) and the error items (Q5 TypeError; Q7 KeyError) were each produced by running the code in Python, not hand-traced. Distractors are plausible mis-traces (Q3 5 = counting duplicates; Q7/Q8 treating a missing-key lookup as None; Q5-A assuming a tuple is mutable).
Item-bank entries (for variants + the midterm/final)
All ten items are tagged course=CSCI1101 · week=10 · objective=6 · topic=tuples-dictionaries-sets and deposited in Item Bank: Week 10 — Tuples, Dictionaries & Sets. The cumulative final (Week 16) and the per-term variant updates draw fresh items from this bank. (Tags: q1 dict-lookup, q2 dict-update, q3 set-dedup, q4 set-membership, q5 tuple-immutable, q6 which-collection, q7 keyerror-debug, q8 keyerror-vs-none, q9 true-statements, q10 collection-match.)
Canvas placement block
canvas_object = Quizzes::Quiz
title = "Week 10 Quiz — Tuples, Dictionaries & Sets"
assignment_group = "Quizzes"
points_possible = 10
grading_type = points
due_offset_days = 5 # 5 days after module start (Sun Nov 8)
published = true
shuffle_answers = true
ai_permitted = false # AI is not permitted on quizzes
provenance = "~ Prof. Okafor's edition · Fall 2026 · built with thecoursemaker.com"
F-quiz-week-10-qti.xml) ships inside the course's .imscc package — it lands in the Canvas gradebook on import.~ Prof. Okafor's edition · Fall 2026 · built with thecoursemaker.com