Week 10 Quiz
Predict, then check: what does this program print?
trip = ("Dock 4", "Dock 9", 12) print(trip[2])Select one.
- 12
- Dock 9
- 3
- TypeError
Predict, then check: what happens when this program runs?
spot = (3, 4) spot[0] = 9 print(spot)Select one.
- It prints (9, 4)
- It stops with TypeError and prints nothing
- It prints (3, 4)
- It prints 9 4
Predict, then check: what does this program print?
a = 1 b = 2 a, b = b, a print(a, b)Select one.
- 1 2
- 2 2
- 2 1
- 1 1
Predict, then check: what does this program print?
log = {"river book": 120, "atlas": 85} log["field notes"] = 40 log["atlas"] = log["atlas"] + 15 print(log["atlas"])Select one.
- 85
- 15
- 40
- 100
Predict, then check: what does this program print?
log = {"atlas": 85} print(log["comics"])Select one.
- KeyError
- None
- 0
- 85
Predict, then check: what does this program print?
log = {"river book": 120, "atlas": 85} print(85 in log)Select one.
- True
- False
- KeyError
- None
Predict, then check: what does this program print?
words = ["red", "blue", "red", "red", "blue"] counts = {} for w in words: counts[w] = counts.get(w, 0) + 1 print(counts)Select one.
- {'red': 2, 'blue': 3}
- {'red': 1, 'blue': 1}
- {'red': 3, 'blue': 2}
- {'blue': 2, 'red': 3}
Predict, then check: what does this program print?
d = {} d["zebra"] = 1 d["apple"] = 2 d["mango"] = 3 print(list(d))Select one.
- ['apple', 'mango', 'zebra']
- ['mango', 'apple', 'zebra']
- ['zebra', 'mango', 'apple']
- ['zebra', 'apple', 'mango']
Select every program that stops with an error when it runs. Predict first, then run each one to check.
Select every option that applies.
spot = (3, 4) spot[0] = 9shelf = {["atlas"]: 85}log = {"atlas": 85} print(log.get("comics", 0))print(len({1, 2, 2, 3}))print(type({}))
True or false: this program prints not logged yet, because the test title in log is False, so only the else branch runs.
log = {"river book": 120, "atlas": 85} title = "comics" if title in log: print(log[title]) else: print("not logged yet")True or false.
- True
- False
Built with The Course Maker · samples.thecoursemaker.com