Last active
November 9, 2019 07:08
-
-
Save sangwon090/5b711ecd144684fcb35f8f5d27ee3fb4 to your computer and use it in GitHub Desktop.
[Python] Reverse Polish Notation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stack = [] | |
for i in input().split(' '): | |
if i.isdigit(): | |
stack.append(int(i)) | |
else: | |
a = stack.pop() | |
b = stack.pop() | |
if i == '+': | |
stack.append(a + b) | |
elif i == '-': | |
stack.append(b - a) | |
elif i == '*': | |
stack.append(a * b) | |
elif i == '/': | |
stack.append(b / a) | |
elif i == '%': | |
stack.append(b % a) | |
print(stack.pop()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment