Lucretiel / genetics

A python library for genetic algorithms
GNU Lesser General Public License v2.1
234 stars 61 forks source link

Hello World example #5

Open pincher-chen opened 7 years ago

pincher-chen commented 7 years ago

$ python3 test_1.py Traceback (most recent call last): File "test_1.py", line 45, in best, best_score, average_score = dna_stats(population) File "test_1.py", line 37, in dna_stats average_score = sum(member.score for member in population) / len(population) TypeError: unsupported operand type(s) for +: 'int' and 'method'

liuruoze commented 6 years ago

The reason is that there is a missing of '()' after score, try this code.

def dna_stats(population):
    '''Best DNA, best score, average score'''
    best_dna = max(population)
    best_score = best_dna.score
    average_score = sum(member.score() for member in population) / len(population)

    return best_dna, best_score, average_score