Question DSA-STK-0042
MediumWhat is the output of this code?
def evalp(tokens):
st = []
for t in tokens:
if t in "+-*/":
b, a = st.pop(), st.pop()
st.append(a + b if t == "+" else a - b if t == "-" else a * b if t == "*" else a // b)
else:
st.append(int(t))
return st[0]
print(evalp("5 1 2 + 4 * + 3 -".split()))
- A.
12
- B.
14
- C.
Sign up free to see the answer and a step-by-step explanation.