Question 6
Back to Exercise
What is the output of the following Python program?
def describe(cmd):
match cmd.split():
case ["go", direction]:
return f"moving {direction}"
case ["pick", "up", item]:
return f"picking {item}"
case ["quit" | "exit"]:
return "bye"
case _:
return "unknown"
for c in ["go north", "pick up lamp", "exit", "go north fast"]:
print(describe(c))
- A moving north picking lamp bye moving north
- B moving north unknown bye unknown
- C moving north picking up bye unknown
- D moving north picking lamp bye unknown Correct
Correct Answer: Option D
["go", direction] matches only a two-word list, so "go north fast" (three words) falls through to case _.
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!