Advertisement
Guest User

1st

a guest
Feb 25th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. import math
  2. from collections import deque
  3.  
  4. the_ugly_expression = input().split()
  5. current_nums = deque([])
  6.  
  7. check = True
  8.  
  9. for symbol in the_ugly_expression:
  10. if symbol.isdigit() or len(symbol) >= 2:
  11. current_nums.append(symbol)
  12.  
  13. else:
  14. if check and (symbol == "/" or symbol == "*"):
  15. result = 1
  16. check = False
  17. elif check:
  18. result = 0
  19. check = False
  20.  
  21. while len(current_nums) >= 2:
  22. num = current_nums.popleft()
  23. next_num = current_nums.popleft()
  24. if symbol == "/":
  25. total = math.floor(eval(f"{num} {symbol} {next_num}"))
  26. else:
  27. total = eval(f"{num} {symbol} {next_num}")
  28. current_nums.appendleft(total)
  29.  
  30.  
  31. print(current_nums.pop())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement