|
@ -1,3 +1,7 @@ |
|
|
|
|
|
# BELLYNCK Manon |
|
|
|
|
|
# GUILLAUMIN-TORRES Ambre |
|
|
|
|
|
# COVIN Clara |
|
|
|
|
|
|
|
|
class Expression: |
|
|
class Expression: |
|
|
"""représente une expression arithmétique sous forme d'un arbre""" |
|
|
"""représente une expression arithmétique sous forme d'un arbre""" |
|
|
def __init__ (valeur_racine, fils_gauche, fils_droit): |
|
|
def __init__ (valeur_racine, fils_gauche, fils_droit): |
|
@ -5,9 +9,21 @@ class Expression: |
|
|
self.gauche = fils_gauche |
|
|
self.gauche = fils_gauche |
|
|
self.droit = fils_droit |
|
|
self.droit = fils_droit |
|
|
|
|
|
|
|
|
def évalue (self) : |
|
|
def évalue (self) : #pas fini |
|
|
if fils_gauche == None and fils_droit == None : |
|
|
if fils_gauche == None and fils_droit == None : |
|
|
return |
|
|
return |
|
|
return évalue |
|
|
if self.valeur == '+': |
|
|
|
|
|
return gauche_val + droite_val |
|
|
|
|
|
elif self.valeur == '-': |
|
|
|
|
|
return gauche_val - droite_val |
|
|
|
|
|
elif self.valeur == '*': |
|
|
|
|
|
return gauche_val * droite_val |
|
|
|
|
|
|
|
|
|
|
|
def __str__(self): |
|
|
|
|
|
result = "" |
|
|
|
|
|
if self.droite: |
|
|
|
|
|
result = result + str(self.droite) |
|
|
|
|
|
result = resutl + str(self.valeur) + "\n" """le "/n" c'est pour avoir une nouvelle ligne de l'arbre""" |
|
|
|
|
|
if self.gauche: |
|
|
|
|
|
result += str(self.gauche) |
|
|
|
|
|
return result |