#!/usr/bin/python
# Command-line calculator, 2022-09-23
import sys
from math import *
if hasattr(sys, "set_int_max_str_digits"):
sys.set_int_max_str_digits(0)
if len(sys.argv) <= 1:
print("command-line calculator: "
"use python syntax right in the command line.\n"
"all math functions are imported: "
"https://docs.python.org/3/library/math.html")
sys.exit(0)
def x_is_times(s):
if s == "x": return "*"
if s == "xx": return "**"
return s
expr = " ".join(map(x_is_times, sys.argv[1:]))
try:
val = eval(expr)
print(val)
except SyntaxError:
print("syntax error")
sys.exit(1)