- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluatePostFix.py
More file actions
Latest commit
37 lines (30 loc) · 514 Bytes
/
Copy pathevaluatePostFix.py
File metadata and controls
37 lines (30 loc) · 514 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
defevalPost(a):
res=[]
fornina:
ifn.isdigit():
res.append(n)
else:
try:
a=res.pop()
b=res.pop()
except:
print"error in key"
res.append(cal(int(b),int(a),n))
returnres.pop()
defcal(a,b,op):
ifop=='*':
returna*b
elifop=='+':
returna+b
elifop=='-':
returna-b
else:
try:
returna/b
except:
print"divide by zero"
a=['2','3','4','+','*']
a=['2','3','*','5','2','*','+']
#a=-+*23*549
a=['9','4','5','*','3','2','*','+','-']
printevalPost(a)