summaryrefslogtreecommitdiff
path: root/comp/work/54/rpn.py
blob: 053a256c1e47506c3a90ab277750c58d72a3cd6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
def eval(expr):
    s = []
    for i in expr.split():
        if i.isdigit():
            s.push(int(i))
        else:
            a = s.pop()
            b = s.pop()
            match i:
                case '+':
                    s.push(b + a)
                case '-':
                    s.push(b - a)
                case '*':
                    s.push(b * a)
                case '/':
                    s.push(b / a)

    print(s.pop())

eval("1 2 +")