Objective
The match statement (Python 3.10 or later) compares a value against several patterns, even structures such as lists. It is ideal for interpreting commands such as "add 2 3".
Instructions
- Read a line and split it with
split()into a list. - Use
matchwith the patterns["add", a, b],["sub", a, b]and["mul", a, b]to add, subtract and multiply integers and showResult: x. - With
["div", a, b]divide showing the result with two decimals, but if the divisor is"0"showDivision by zero(put that case first). - Any other command (
case _:) showsUnknown operation.
add 2 3
Result: 5
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise