match Statement
Completed
Read a command: start, stop, pause or anything else. Using match/case, print Starting, Stopping, Paused or Unknown command: X.
Input
One word.
Output
One line.
Example
Input
start
Output
Starting
Editor
Python
Hints
match was added in Python 3.10.
case _: matches anything (the default).
Solution explanation
match compares a value against patterns. It can also destructure lists and objects, which later labs use.
Show solution
cmd = input()
match cmd:
case "start":
print("Starting")
case "stop":
print("Stopping")
case "pause":
print("Paused")
case _:
print(f"Unknown command: {cmd}")