title: Python List Index Out Of Range in For loop
body: <p>Please I have no clue what's happening...</p>
  
  <pre><code>import random
  o = 0
  p = 5
  n = 5
  z = -1
  y = -1
  a = ["x" * n]
  b = [7,7,1,8,2]
  
  while o != p:
       for x in range(n):
           z += 1
           y += 1
           while a[z] != b[y]
                a[z] = random.randint(0,9)
           y += 1
           print(str(b[0:y])
           y -= 1
           o += 1
  </code></pre>
  
  <p>I hope everything is understandable. My code is kinda messy and gets polished so I changed the variables. The error is here ALWAYS when the 2nd PRINT HAPPENS, only and always when the b is printed 2nd times no matter what the n is except n = 1: </p>
  
  <pre><code>while a[z] != b[y]
  IndexError: list index out of range
  </code></pre>