如何在运算中使用算术运算符(由用户作为字符串输入)?我可以打印操作本身,但我想打印解决方案!
这是我笨拙的尝试:
# Initialise variables
x = 2
y = 3
# Prompt the user for an arithmetic operator
operator = input("Please enter *, /, +, or - : ")
# Calculate the operation
result = (str(x) + operator + str(y))
# Display the result
print(result)