Skip to content

Commit 47c6298

Browse files
committed
Replace format() str method by f-string
1 parent 900df55 commit 47c6298

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ num_genes = len(function_inputs)
183183
last_fitness = 0
184184
def callback_generation(ga_instance):
185185
global last_fitness
186-
print("Generation = {generation}".format(generation=ga_instance.generations_completed))
187-
print("Fitness = {fitness}".format(fitness=ga_instance.best_solution()[1]))
188-
print("Change = {change}".format(change=ga_instance.best_solution()[1] - last_fitness))
186+
print(f"Generation = {ga_instance.generations_completed}")
187+
print(f"Fitness = {ga_instance.best_solution()[1]}")
188+
print(f"Change = {ga_instance.best_solution()[1] - last_fitness}")
189189
last_fitness = ga_instance.best_solution()[1]
190190

191191
# Creating an instance of the GA class inside the ga module. Some parameters are initialized within the constructor.
@@ -204,15 +204,15 @@ ga_instance.plot_fitness()
204204

205205
# Returning the details of the best solution.
206206
solution, solution_fitness, solution_idx = ga_instance.best_solution()
207-
print("Parameters of the best solution : {solution}".format(solution=solution))
208-
print("Fitness value of the best solution = {solution_fitness}".format(solution_fitness=solution_fitness))
209-
print("Index of the best solution : {solution_idx}".format(solution_idx=solution_idx))
207+
print(f"Parameters of the best solution : {solution}")
208+
print(f"Fitness value of the best solution = {solution_fitness}")
209+
print(f"Index of the best solution : {solution_idx}")
210210

211211
prediction = numpy.sum(numpy.array(function_inputs)*solution)
212-
print("Predicted output based on the best solution : {prediction}".format(prediction=prediction))
212+
print(f"Predicted output based on the best solution : {prediction}")
213213

214214
if ga_instance.best_solution_generation != -1:
215-
print("Best fitness value reached after {best_solution_generation} generations.".format(best_solution_generation=ga_instance.best_solution_generation))
215+
print(g"Best fitness value reached after {ga_instance.best_solution_generation} generations.")
216216

217217
# Saving the GA instance.
218218
filename = 'genetic' # The filename to which the instance is saved. The name is without extension.

0 commit comments

Comments
 (0)