3
I created an array and filled it with 100 [0] (because I don’t know a better way to do it) and after that I wanted to change these values using a loop for
within another loop for
. But what happens is that after the inside loop, when it comes out, all the values are reset again...
Here is the code (there are three prints there that you can see that inside the for
it changes to the value I want but when the for
, he goes back to being zero):
mediasCa = []
for k in range(0,itera):
mediasCa.append(0)
for j in range(0,99):
a = quant
print(mediasCa[j])
for i in range(0,itera):
bola = randint(1,quant)
if bola < a:
a -= 1
else:
a += 1
print(mediasCa[i])
mediasCa[i] = mediasCa[i] + a
print(mediasCa[i])
I already found the error '-', I’m iterating the vector out of the right loop... missing a tab =p
– Pedro Almeida
Post the correct code as response.
– Laerte
I don’t know how to edit right using markdown, but:
mediasCa = []
 
 for k in range(0,itera):
 mediasCa.append(0)
 
 
 for j in range(0,99):
 aux = []
 a = quant
 
 for i in range(0,itera):
 bola = randint(1,quant)
 if bola < a:
 a -= 1
 else:
 a += 1
 mediasCa[i] = mediasCa[i] + a
– Pedro Almeida
As reply Peter, here is comment.
– Laerte
Sorry, first time here.
– Pedro Almeida
No problem is that when you’ve found the solution it’s always good to post the answer.
– Laerte