Question 5
Back to Exercise
Python refuses to run the program below. Which statement correctly describes the problem?
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!