title: How to fix "IndexError: list assignment index out of range" error in Python?
body: <p>I'm a beginner to Python with very little experience in coding. I've started writing a Python program to multiply two matrices.
  The following code gives me output for square matrices but gives me the following error when I enter, say for example, m=2, n=3, p=3, q=2:</p>
  
  <pre><code>"a[i][j] = (int(input()))
  IndexError: list assignment index out of range"
  </code></pre>
  
  <p>Could anybody please help me out with this? Thank you!</p>
  
  <p>HERE'S THE CODE:</p>
  
  <pre><code>m=int(input('Enter number of rows of matrix I:'))
  n=int(input('Enter number of columns of matrix I:'))
  
  p=int(input('Enter number of rows of matrix II:'))
  q=int(input('Enter number of columns of matrix II:'))
  
  
  if n!=p:
      print('\nThese matrices cannot be multiplied!')
  else:
      a = [[[] for i in range(m)] for j in range(n)]
      b = [[[] for i in range(p)] for j in range(q)]
      c = [[[] for i in range(m)] for j in range(q)]
  
  print('Enter elements of matrix I:')
  for i in range(m):
      for j in range(n):
          print('Element (', i, ',', j, '):', end="")
          a[i][j] = (int(input()))
  
  print('Enter elements of matrix II:')
  for i in range(p):
      for j in range(q):
          print('Element (', i, ',', j, '):', end="")
          b[i][j] = (int(input()))
  sum = 0
  for i in range(m):
      for j in range(q):
          for k in range(n):
              sum = sum + a[i][k] * b[k][j]
          c[i][j] = sum
          sum = 0
  print('\nResultant matrix:')
  for i in range(m):
      for j in range(q):
          print(c[i][j],"\t\t\t",end="")
      print()
  </code></pre>
  
  <p><strong>strong text</strong></p>