The program below stops with an error. Which statement correctly describes the problem?
resolution = (1920, 1080)
resolution[0] = 1280
print(resolution)
Rebind the name to a new tuple, or use a list if the values must change.
Tuples · Exercise 3 of 4
Each Python program has a tuple mistake: an exception at run time, or a logical bug such as a missing comma. Choose the option that names the real problem.
The program below stops with an error. Which statement correctly describes the problem?
resolution = (1920, 1080)
resolution[0] = 1280
print(resolution)
Rebind the name to a new tuple, or use a list if the values must change.
The program below stops with an error. Which statement correctly describes the problem?
weekdays = ("Mon", "Tue", "Wed")
weekdays.append("Thu")
print(weekdays)
Tuples only have count() and index().
The program below stops with an error. Which statement correctly describes the problem?
record = ("Asha", 21, "CSE")
name, age = record
print(name, age)
Unpacking is strict about the count unless a starred name absorbs the extras.
The program below stops with an error. Which statement correctly describes the problem?
line = "Ravi,78"
name, marks, grade = line.split(",")
print(name, marks, grade)
Missing values are not filled with None. Check len() first, or use a starred name.
The program should print the single colour "red". Which statement correctly identifies the bug?
colors = ("red")
for c in colors:
print(c)
The trailing comma makes a one-item tuple.
The program below stops with an error. Which statement correctly describes the problem?
routes = {}
routes[("Delhi", ["Agra", "Jaipur"])] = 514
print(routes)
A tuple is hashable only if everything inside it is.
The program below stops with an error. Which statement correctly describes the problem?
scores = (72, 85)
scores = scores + 91
print(scores)
Wrap the new item in a one-item tuple.
The program below stops with an error. Which statement correctly describes the problem?
ranks = ("Asha", "Ravi", "Meera")
print("Kiran is rank", ranks.index("Kiran") + 1)
Tuples have no find(); test membership before calling index().
The scores, once sorted, should match the expected tuple. Which statement correctly identifies the bug?
scores = (85, 72, 91)
expected = (72, 85, 91)
print("match" if sorted(scores) == expected else "no match")
[72, 85, 91] == (72, 85, 91) is False because the types differ.
The program below stops with an error. Which statement correctly describes the problem?
team = ("Alpha", ["Asha", "Ravi"])
team[1] += ["Meera"]
print(team)
A famous Python puzzle: the list really does gain "Meera", yet the statement raises. Call the list's own method instead.
Timed online tests with instant scores and explanations.