print('Enter a mathematical expression: ')
expression = input()
space = expression.find(' ')
oprand1 = expression[0 : space]
oprand1 = int(oprand1)
op = expression.find('+' or '*' or '-' or '/')
oprand2 = expression[op + 1 : ]
oprand2 = int(oprand2)
if op == '+':
ans = int(oprand1) + int(oprand2)
print(ans)
因此可以說用戶在每個字符之間輸入2 + 3的空格。我怎樣才能打印2 + 3 = 5?我需要代碼來處理所有操作。評估一個數學表達式(python)
您使用的是哪個版本的python? http://stackoverflow.com/questions/1093322/how-do-i-check-what-version-of-python-is-running-my-script – AbrahamB
Anaconda spyder –
你可以打印'import sys'的結果嗎' sys.version' – polka