• API
• FAQ
• Tools
• Archive
SHARE
TWEET G DrunkBear  Mar 20th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. from math import *
2.
3. inp = input().split()
4. stack = []
5. s = ''
6.
7. for i in inp:
8.     if i == '+':
9.         if len(stack) < 2:
10.             s = 'ERROR'
11.             break
12.         else:
13.             stack.append(stack.pop(-1) + stack.pop(-1))
14.
15.     elif i == '-':
16.         if len(stack) < 2:
17.             s = 'ERROR'
18.             break
19.         else:
20.             stack.append(-stack.pop(-1) + stack.pop(-1))
21.
22.     elif i == '*':
23.         if len(stack) < 2:
24.             s = 'ERROR'
25.             break
26.         else:
27.             stack.append(stack.pop(-1) * stack.pop(-1))
28.
29.     elif i == '/':
30.         if len(stack) < 2:
31.             s = 'ERROR'
32.             break
33.         else:
34.             stack.append(1 / stack.pop(-1) * stack.pop(-1))
35.
36.     elif i == 'abs':
37.         if len(stack) == 0:
38.             s = 'ERROR'
39.             break
40.         else:
41.             stack.append(abs(stack.pop(-1)))
42.
43.     elif i == 'sin':
44.         if len(stack) == 0:
45.             s = 'ERROR'
46.             break
47.         else:
48.             stack.append(sin(stack.pop(-1)))
49.
50.     elif i == 'cos':
51.         if len(stack) == 0:
52.             s = 'ERROR'
53.             break
54.         else:
55.             stack.append(cos(stack.pop(-1)))
56.
57.     elif i == 'sqrt':
58.         if len(stack) == 0:
59.             s = 'ERROR'
60.             break
61.         else:
62.             stack.append(sqrt(stack.pop(-1)))
63.
64.     else:
65.         stack.append(int(i))
66.
67.     #print(stack)
68.
69. if len(stack) != 1:
70.     s = 'ERROR'
71. if s != 'ERROR':
72.     s = '{0:.3f}'.format(stack)
73. print(s)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!

Top