Created
June 23, 2020 19:52
-
-
Save andriiburka/aa0397c08c73dfa37a5f62399ff1e263 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from _collections import deque | |
inp_raw = input().split() | |
operator = ["*", "+", "-", "/"] | |
evaluate_list = deque() | |
result = 0 | |
for el in inp_raw: | |
result = 0 | |
if el not in operator: | |
current_digit = int(el) | |
evaluate_list.append(current_digit) | |
else: | |
if el == "*": | |
result = 1 | |
while evaluate_list: | |
result *= evaluate_list.popleft() | |
evaluate_list.appendleft(result) | |
elif el == "/": | |
result = 1 | |
while evaluate_list: | |
result /= evaluate_list.popleft() | |
evaluate_list.appendleft(result) | |
elif el == "+": | |
while evaluate_list: | |
result += evaluate_list.popleft() | |
evaluate_list.appendleft(result) | |
elif el == "-": | |
while evaluate_list: | |
number = evaluate_list.popleft() | |
evaluate_list.appendleft(result) | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment