Chapters
Python114 chapters

Exercises

Match

3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.

Exercise 1

Match the command: start prints Starting, stop prints Stopping, anything else prints Unknown.

Python
command = "stop"
# match on command
Exercise 2

Match the point and print origin, on the x axis, or elsewhere.

Python
point = (5, 0)
# match the pair
Exercise 3

Add a guard so negative numbers are reported separately.

Python
value = -3

match value:
    case n if n > 10:
        print(n, "large")
    case n:
        print(n, "small")