vendredi 20 juillet 2018

for loop inside if giving syntex error in python

In this code, it is giving syntax error on else:, if I remove for loop above else, it works fine.. not being able to find the problem..

    if self.first_pass:
        init_classifier=random.sample(self.list_of_classifier.keys(),5)
        possible_classifier=[x for x in all_classifier if x not in init_classifier]
        for z in range(0,self.ant_count):
            self.ants.append(ant(init_classifier, possible_classifier, self.list_of_classifier, self.pheromone_list,first_pass=True)
    else:
        for z in range(self.ant_count):
            init_classifier=random.sample(self.list_of_classifier.keys(),5)
            possible_classifier=[x for x in all_classifier if x not in init_classifier]
            self.ants[z].__init__(init_classifier, possible_classifier,self.list_of_classifier, self.pheromone_list,first_pass=False)
    for z in range(self.ant_count):
        self.ants[z].run()

else: ^ SyntaxError: invalid Syntax

Aucun commentaire:

Enregistrer un commentaire