Question 9
Back to Exercise
The setting is read as text and should switch debug mode off. Which statement correctly identifies the bug?
setting = "False" # value read from a settings file
debug = bool(setting)
print("Debug mode ON" if debug else "Debug mode OFF")
- A bool() cannot take a string
- B The conditional expression is written backwards
- C Any non-empty string is truthy, so bool("False") is True; compare the text instead: setting.lower() == "true" Correct
- D setting must be in single quotes
Correct Answer: Option C
bool() tests emptiness, not meaning. Parse text flags explicitly.
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!