LearnFrenzy
Sign in Take a free test

Variables and Data Types · Find the Error · Question 9

Bug: bool("False") is True Answer, explanation & discussion

  • Find the error
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 9 Back to Exercise

The setting is read as text and should switch debug mode off. Which statement correctly identifies the bug?

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

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links