Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Pile_Entier:
- def __init__(self, taille =100):
- self.taille = taille
- self.pile = []
- def empiler(self, element):
- assert not self.est_Pleine()
- self.pile.append(element)
- def depiler(self):
- assert not self.est_Vide()
- return self.pile.pop()
- def sommet(self):
- return self.pile[-1]
- def est_Vide(self):
- return len(self.pile) == 0
- def est_Pleine(self):
- return len(self.pile) == self.taille
- def purger(self):
- assert not self.est_Vide()
- i = taille - 1
- while i > -1:
- self.pile.pop()
- i -= 1
- def afficher(self):
- assert not self.est_Vide()
- for i in self.pile:
- print(i)
- class Calculatrice():
- def __init__(self):
- self.pile = Pile_Entier()
- def npi(self,saisie):
- saisie = saisie.split()
- print(saisie)
- op =("+-*")
- for c in saisie:
- if c not in op:
- self.pile.empiler(c)
- else:
- a = int(self.pile.depiler())
- b = int(self.pile.depiler())
- if c == "+":
- self.pile.empiler(b+a)
- elif c == "-":
- self.pile.empiler(b - a)
- else:
- self.pile.empiler(b * a)
- return self.pile.depiler()
- c = Calculatrice()
- print(c.npi("2 3 + 4 - "))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement