Solution: Calculator eval
examples/basics/calculator_argv_eval.py
import sys def main(): if len(sys.argv) != 4: exit(f"Usage: {sys.argv[0]} NUMBER OPERATOR NUMBER") command = sys.argv[1] + sys.argv[2] + sys.argv[3] print(command) res = eval(command) print(res) main()
$ python examples/basics/calculator_argv_eval.py 2 + 3 5 $ python examples/basics/calculator_argv_eval.py 2 '*' 3 6
- Now forget this and don't use eval for the next few years!