Я в 10-м году и очень плохо умею кодировать.По сути, я пытаюсь создать действительно простой симулятор эволюции, и до сих пор он работал хорошо, но я столкнулся с этой ошибкой при использовании списков для определения переменных.Я приложил полный код.
#************************#
#* Jadday's Amazing *#
#* Evolution Simulator *#
#************************#
import random
print("The Evolution Starts Here")
numcs = 100
def generation1():
global numcs
profiles = []
maxscore = 0
minscore = 100
x = 0
for i in range(0,numcs):
a = random.randint(0,75)
b = random.randint(a,100)
score = random.randint(a,b)
name = [a,b]
x = str(x)
x = int(x)
x = x + 1
if score > maxscore:
maxscore = score
score = str(score)
best = score
score = int(score)
if score < minscore:
minscore = score
score = str(score)
worst = score
score = int(score)
score = str(score)
profile = score
score = int(score)
profiles.append(score)
profiles = [int(x) for x in profiles]
profiles.sort()
print(profile)
print("")
print("")
print("The best was:")
print(best)
print("")
print("The worst was:")
print(worst)
numcs = numcs // 2
templength = len(profiles)
length = templength // 2
for x in range(0,length):
del profiles[0]
print("")
print(profiles)
def generation():
global numcs
profiles = []
maxscore = 0
minscore = 100
x = 0
for i in range(0,numcs):
a = profiles[i]
a = a / 2
b = profiles[i]
b = b * 2
score = random.randint(a,b)
name = [a,b]
x = str(x)
x = int(x)
x = x + 1
if score > maxscore:
maxscore = score
score = str(score)
best = score
score = int(score)
if score < minscore:
minscore = score
score = str(score)
worst = score
score = int(score)
score = str(score)
profile = score
score = int(score)
profiles.append(score)
profiles = [int(x) for x in profiles]
profiles.sort()
print(profile)
print("")
print("")
print("The best was:")
print(best)
print("")
print("The worst was:")
print(worst)
numcs = numcs // 2
templength = len(profiles)
length = templength // 2
for x in range(0,length):
del profiles[0]
print("")
print(profiles)
generation1()
for x in range(0,6):
generation()
numcs = numcs // 2
Ошибка в строке 'a = profile [i]' при определении 'generation'.Скорее всего, я делаю симулятор действительно неэффективно, но я пытаюсь сделать его проще.Если кто-нибудь знает, как решить эту проблему, я был бы признателен.Спасибо