You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
# BELLYNCK Manon
|
|
|
|
# GUILLAUMIN-TORRES Ambre
|
|
|
|
# COVIN Clara
|
|
|
|
|
|
|
|
class Expression:
|
|
|
|
"""représente une expression arithmétique sous forme d'un arbre"""
|
|
|
|
def __init__ (valeur_racine, fils_gauche, fils_droit):
|
|
|
|
self.val_racine = valeur_racine
|
|
|
|
self.gauche = fils_gauche
|
|
|
|
self.droit = fils_droit
|
|
|
|
|
|
|
|
def évalue (self) : #pas fini
|
|
|
|
if fils_gauche == None and fils_droit == None :
|
|
|
|
return
|
|
|
|
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
|