Trajet

mail@pastecode.io avatar
unknown
python
2 years ago
970 B
4
Indexable
Never
class Trajet:
    def __init__(self, lst_ville):
        self.lst_ville=[]
        self.long_traj=0
        if(lst_ville!=None):
            self.lst_ville=copy.deepcopy(lst_ville)
            r.shuffle(self.lst_ville)
    
    def calc_longueur(self):
        ville=self.lst_ville[0]
        for i in range(1, len(self.lst_ville)-2):
            self.long_traj+=ville.distance_vers(self.lst_ville[i])
            ville=self.lst_ville[i]

    def est_valide(self):
        count=0
        for i in range(len(self.lst_ville)):
            count=0
            for j in range(len(self.lst_ville)):
                if(self.lst_ville[i].name==self.lst_ville[j].name):
                    count+=1
                    if(count==2):
                        return False
        return True
    
    def __str__(self):
        lst=[]
        for i in range(len(self.lst_ville)):
            lst.append(str(self.lst_ville[i]))
        return str(lst)