# 如何解决switch 条件下的PYTHON零分误差

def reversePolishNotation(tokens):
operators = [ "+", "-", "*", "/" ]
stack = []

for token in tokens:
if token not in operators:
stack.append(int(token))
else:
firstNumber = stack.pop()
secondNumber = stack.pop()

switcher = {
"+": firstNumber + secondNumber,
"-": secondNumber - firstNumber,
"*": firstNumber * secondNumber,
"/": secondNumber / firstNumber
}

sum = switcher.get(token)

stack.append(int(sum))

return int(stack[-1])

resp = reversePolishNotation(["4", "-7", "2", "6", "+", "10", "-", "/", "*", "2", "+", "3", "*", "0", "*"])


## 推荐答案

def reversePolishNotation(tokens):
operators = [ "+", "-", "*", "/" ]
stack = []

for token in tokens:
if token not in operators:
stack.append(int(token))
else:
firstNumber = stack.pop()
secondNumber = stack.pop()

if token == "+":
sum = firstNumber + secondNumber
elif token == "-":
sum = secondNumber - firstNumber
elif token == "/":
sum = secondNumber / firstNumber
else:
sum = firstNumber * secondNumber

stack.append(int(sum))

return int(stack[-1])