So I am working on a small assistant which is supposed to read websites, convert units etc. Me and my friend are still working on getting the first commands up, so we tried to make a calculator. It is supposed to be able to calculate calculations with multiple operators and brackets, like the Python Shell does. But there seems to be no way to just input a string into the shell to use it for this. All calculator codes we found were very long and couldn't handle more than one operator. Do we have to use a long script for this or is there an easier way? My partner wrote something like this, it seemed to be the easiest option:
calc = input()
calc2 = calc.split()
num1 = float(calc2[0])
num2 = float(calc2[2])
operator = calc2[1]
if operator == "+":
print(num1 + num2)
elif operator == "-":
print(num1 - num2)
elif operator == ("*" or "x"):
print(num1 * num2)
elif operator == ("/" or ":"):
print(num1 / num2)
elif operator == "//":
print(num1 // num2)
elif operator == "**":
print(num1 ** num2)
elif operator == "%":
print(num1 % num2)
else:
print("ERROR")