Structural Pattern Matching

Lab Python Advanced 30 points

Read commands and handle them with match on the split list: go DIRECTION, pick ITEM [ITEM...], quit, anything else. Print moving DIRECTION, picked N items: ..., bye or ?.

Input

Line 1: n. Then n commands.

Output

n lines.

Example

Input

5
go north
pick key lamp
pick
quit
dance now

Output

moving north
picked 2 items: key, lamp
?
bye
?
Sample input available Sample output available
Editor
Python

Hints

case ["go", direction] matches a 2-item list starting with go.

*items captures the rest; add if items as a guard.

Solution explanation

Pattern matching can destructure sequences and add guards — far clearer than nested ifs on lengths and indexes.

Show solution
for _ in range(int(input())):
    match input().split():
        case ["go", direction]:
            print(f"moving {direction}")
        case ["pick", *items] if items:
            print(f"picked {len(items)} items: {', '.join(items)}")
        case ["quit"]:
            print("bye")
        case _:
            print("?")
Output
Answer
HOME LEARN COMMUNITY DASHBOARD