Updated repr/str

This commit is contained in:
SimpleArt
2020-11-16 20:51:09 -05:00
parent 2efebc4bcd
commit 0d8fb6147c
3 changed files with 14 additions and 19 deletions

View File

@ -55,20 +55,10 @@ class Chromosome:
def __repr__(self): def __repr__(self):
"""Format the repr() output for the chromosome""" """Create a backend string of the chromosome. Ex '1, 2, 3'."""
output_str = '' return ', '.join(repr(gene) for gene in self.gene_list)
for gene in self.gene_list:
output_str += gene.__repr__()
return output_str
def __str__(self): def __str__(self):
"""Create a string of the chromosome. Ex chromsome = 1,2,3""" """Create a printable string of the chromosome. Ex '[1][2][3]'."""
output_str = '' return ''.join(str(gene) for gene in self.gene_list)
for gene in self.gene_list:
if gene == self.gene_list[0]:
output_str += str(gene.get_value())
else:
output_str += ',' + str(gene.get_value())
return output_str

View File

@ -29,5 +29,10 @@ class Gene:
def __repr__(self): def __repr__(self):
"""Format the repr() output value""" """Create a backend string of the chromosome. Ex '1'."""
return f'[{self.value}]' return str(self.value)
def __str__(self):
"""Create a printable string of the chromosome. Ex '[1]'."""
return f'[{str(self.value)}]'

View File

@ -148,11 +148,11 @@ class Population:
"""Sets the fitness value of the population""" """Sets the fitness value of the population"""
self.fitness = fitness self.fitness = fitness
'''
def __repr__(self): def __repr__(self):
"""Returns a string representation of the entire population""" """Returns a backend string representation of the entire population"""
pass pass
'''
def print_all(self): def print_all(self):
"""Prints information about the population in the following format: """Prints information about the population in the following format: