I have already pointed out that you have forgot the equal sign in creatureNumber + 1
, so you have updated your question with the corrected code, but are still not getting the expected result. OK. Here the next main issue your code has:
If you have a list like creatures = [1,1,1,1]
and you want change it to [1,2,3,4]
you have to do it as follows:
for i, _ in enumerate(creatures):
creatures[i] = i+1
Now le's go back to coding.
It is very hard to guess what you want to achieve from the code you have provided, but I will try it just by chance anyway:
import random
creatures = [1,1,1,1]
def Evolve(evolution, creatures):
print(creatures)
creatureNumber = 0
if evolution == 0:
print("First Generation:")
for i, item in enumerate(creatures):
creatureIndex = creatureNumber + 1
creatureNumber += 1
print(" Creature", creatureIndex, ":", creatures[i])
randomMutation = random.randint(-1, 2)
creatures[i] += randomMutation
else:
print("Evolution", evolution, ":")
for i, item in enumerate(creatures):
creatureIndex = creatureNumber + 1
creatureNumber += 1
print(" Creature", creatureIndex, ":", creatures[i])
randomMutation = random.randint(-1, 2)
creatures[i] += randomMutation
print("")
print(creatures)
print("Leading Creature:", creatures.index(max(creatures))+ 1,":", max(creatures))
print('---')
# EvolveQuestion(evolution, creatures)
Evolve(0, creatures)
Evolve(1, creatures)
Evolve(2, creatures)
Evolve(3, creatures)
Evolve(4, creatures)
Evolve(5, creatures)
The code above is my best guess about what you have intended to achieve and still doesn't in some what it does make any sense, but at least it shows some "evolution". Now I am eager to see if you consider it helpful for you. I will notice it from your comments or if you accept my answer :) .
The code gives as printout:
[1, 1, 1, 1]
First Generation:
Creature 1 : 1
Creature 2 : 1
Creature 3 : 1
Creature 4 : 1
[3, 0, 2, 3]
Leading Creature: 1 : 3
---
[3, 0, 2, 3]
Evolution 1 :
Creature 1 : 3
Creature 2 : 0
Creature 3 : 2
Creature 4 : 3
[3, 1, 4, 2]
Leading Creature: 3 : 4
---
[3, 1, 4, 2]
Evolution 2 :
Creature 1 : 3
Creature 2 : 1
Creature 3 : 4
Creature 4 : 2
[5, 3, 3, 2]
Leading Creature: 1 : 5
---
[5, 3, 3, 2]
Evolution 3 :
Creature 1 : 5
Creature 2 : 3
Creature 3 : 3
Creature 4 : 2
[6, 2, 3, 1]
Leading Creature: 1 : 6
---
[6, 2, 3, 1]
Evolution 4 :
Creature 1 : 6
Creature 2 : 2
Creature 3 : 3
Creature 4 : 1
[5, 3, 4, 0]
Leading Creature: 1 : 5
---
[5, 3, 4, 0]
Evolution 5 :
Creature 1 : 5
Creature 2 : 3
Creature 3 : 4
Creature 4 : 0
[4, 4, 6, 1]
Leading Creature: 3 : 6
---