LearnFrenzy
Sign in Take a free test

Conditional Statements · Find the Error · Question 5

Error: a constant name in a case Answer, explanation & discussion

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

Python refuses to run the program below. Which statement correctly describes the problem?

main.py
QUIT = "q"
command = "x"
match command:
    case QUIT:
        print("Quitting")
    case _:
        print("Other command")
  • A match needs brackets around command
  • B case QUIT: is a capture pattern that matches anything, so the case _ after it is unreachable – Python rejects this; use a literal "q" or a dotted name Correct
  • C QUIT must be lowercase
  • D There is no error; it prints Other command
Correct Answer: Option B

Python reports "name capture 'QUIT' makes remaining patterns unreachable". Use case "q": or a class constant such as case Command.QUIT:.

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