Question 5
Back to Exercise
The program should print the single colour "red". Which statement correctly identifies the bug?
colors = ("red")
for c in colors:
print(c)
- A for cannot loop over tuples
- B ("red") is just the string "red" in brackets, so the loop walks its characters; write ("red",) Correct
- C print adds newlines between letters
- D The brackets must be square
Correct Answer: Option B
The trailing comma makes a one-item tuple.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!