LearnFrenzy
Sign in Take a free test

Tuples · Find the Error · Question 5

Bug: looping over ("red") prints letters Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 5 Back to Exercise

The program should print the single colour "red". Which statement correctly identifies the bug?

main.py
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links