-
Notifications
You must be signed in to change notification settings - Fork 2
/
postfija.py
27 lines (24 loc) · 866 Bytes
/
postfija.py
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
# -*- coding: utf-8 -*-
from Pila import Pila
class postfija:
arbolbase = Pila()
entrada = input()
lista = entrada.split(" ")
#print(lista)
for element in lista:
if (element == '+' or element == '-' or element == '*'
or element == '/'):
puntder=float(arbolbase.desapilar())
puntizq=float(arbolbase.desapilar())
if element=='+':
arbolbase.apilar(puntizq + puntder)
if element=='-':
arbolbase.apilar(puntizq - puntder)
if element=='*':
arbolbase.apilar(puntizq * puntder)
if element=='/':
arbolbase.apilar(puntizq / puntder)
else:
#print (element)
arbolbase.apilar(element)
print (arbolbase.desapilar())