Objective
Create a command-line calculator with the argparse module, which validates the arguments for you. The arguments of each test are passed to the program as if you typed them in the terminal (they appear in the test cases).
Instructions
- Define three positional arguments:
a(integer),op(it can only be+,-,xor/, withchoices) andb(integer). - Define the option
--round(integer, default 2): decimals used to round a division. - Show
Result: r. Division isa / brounded withround(value, decimals). - If dividing by 0 call
parser.error(...)with a message;argparseends the program with exit code 2 (just like when an argument is invalid).
Result: 42
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise