+ 5
Genetic algorithm
i wanted to learn more about ai on the way i encounterd genetic algorythms so i tried programing a commonly used practice for genetic algorythm (monkeys typing a line from shakespeare) my code is now not the best but it works for smaller lines now the problem i have is , that the code wont print the count of the latest generation :/ so i would like to ask for some help please :) https://code.sololearn.com/cdqQ67qYXQ45/?ref=app
2 Answers
+ 3
When you are inside in function you need to say to python that gen variable is global. So inside crossover in beginning you need write.
global gen
The error happens because python interpreter is trying to create a local variable called gen.
+ 2
thank you :)