Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inp = input().split()
- stack = []
- s = ''
- for i in inp:
- if i == '+':
- if len(stack) < 2:
- s = 'ERROR'
- break
- else:
- stack.append(str(int(stack[-2]) + int(stack[-1])))
- stack.pop(-2)
- stack.pop(-2)
- elif i == '-':
- if len(stack) < 2:
- s = 'ERROR'
- break
- else:
- stack.append(str(int(stack[-2]) - int(stack[-1])))
- stack.pop(-2)
- stack.pop(-2)
- elif i == '*':
- if len(stack) < 2:
- s = 'ERROR'
- break
- else:
- stack.append(str(int(stack[-2]) * int(stack[-1])))
- stack.pop(-2)
- stack.pop(-2)
- elif i == '/':
- if len(stack) < 2:
- s = 'ERROR'
- break
- else:
- stack.append(str(int(stack[-2]) // int(stack[-1])))
- stack.pop(-2)
- stack.pop(-2)
- else:
- stack.append(i)
- if len(stack) != 1:
- s = 'ERROR'
- if s != 'ERROR':
- s = stack[0]
- print(s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement