• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Dec 11th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. from math import sin, cos, sqrt
2.
3. numbers = []
4. perem = {}
5. string = input().split()
6. while True:
7.     try:
8.         name, value = input().split('=')
9.         perem[name] = float(value)
10.     except Exception:
11.         break
12.
13. try:
14.     for token in string:
15.         if token == '+':
16.             numbers.append(numbers.pop() + numbers.pop())
17.         elif token == '-':
18.             b, a = numbers.pop(), numbers.pop()
19.             numbers.append(a - b)
20.         elif token == '*':
21.             numbers.append(numbers.pop() * numbers.pop())
22.         elif token == '/':
23.             b, a = numbers.pop(), numbers.pop()
24.             numbers.append(a / b)
25.
26.         elif token == 'abs':
27.             numbers.append(abs(numbers.pop()))
28.         elif token == 'sin':
29.             numbers.append(sin(numbers.pop()))
30.         elif token == 'cos':
31.             numbers.append(cos(numbers.pop()))
32.         elif token == 'sqrt':
33.             numbers.append(sqrt(numbers.pop()))
34.
35.         else:
36.             try:
37.                 numbers.append(perem[token])
38.             except KeyError:
39.                 numbers.append(float(token))
40.
41.     if len(numbers) == 1:
42.         print(f'{numbers.pop():.3f}')
43.     else: raise Exception
44. except Exception:
45.     print('ERROR')
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.

Top